Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Dumb solution in Clear category for Voice TV Control by obone
class VoiceCommand:
def __init__(self, channels):
self.ch = channels
self.n = 0
def first_channel(self):
self.n = 0
return self.ch[0]
def last_channel(self):
self.n = len(self.ch) - 1
return self.ch[-1]
def turn_channel(self, n):
self.n = n - 1
return self.ch[self.n]
def next_channel(self):
self.n = self.n + 1 if self.n < len(self.ch) - 1 else 0
return self.ch[self.n]
def previous_channel(self):
self.n = self.n - 1 if self.n > 0 else len(self.ch) - 1
return self.ch[self.n]
def current_channel(self):
return self.ch[self.n]
def is_exist(self, p):
if isinstance(p, int):
return "Yes" if 0 < p < len(self.ch) else "No"
else:
return "Yes" if p in self.ch else "No"
June 19, 2019