Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Microwave Ovens by Sarina
class MicrowaveBase:
MAX_VALUE = 90*60
def __init__(self):
self._time = 0
def set_time(self, value):
time = value.split(':')
self._time = min(self.MAX_VALUE, int(time[0])*60 + int(time[1]))
def add_time(self, value):
if value.endswith('s'):
self._time = min(self.MAX_VALUE, int(value[:-1]) + self._time)
elif value.endswith('m'):
self._time = min(self.MAX_VALUE, int(value[:-1])*60 + self._time)
def del_time(self, value):
if value.endswith('s'):
self._time = max(0, self._time - int(value[:-1]))
elif value.endswith('m'):
self._time = max(0, self._time - (int(value[:-1])*60))
def show_time(self):
return f"{self._time//60:02}:{self._time%60:02}"
class Microwave1(MicrowaveBase):
def show_time(self):
string = super().show_time()
return '_' + string[1:]
class Microwave2(MicrowaveBase):
def show_time(self):
string = super().show_time()
return string[:-1] + '_'
class Microwave3(MicrowaveBase):
pass
class RemoteControl:
def __init__(self, microwave):
self._microwave = microwave
def set_time(self, value):
self._microwave.set_time(value)
def add_time(self, value):
self._microwave.add_time(value)
def del_time(self, value):
self._microwave.del_time(value)
def show_time(self):
return self._microwave.show_time()
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
microwave_1 = Microwave1()
rc_1 = RemoteControl(microwave_1)
rc_1.set_time("05:33")
rc_1.del_time("30s")
rc_1.del_time("2m")
rc_1.show_time()
May 15, 2020