diff --git a/Day 4 Homework - Karen.md b/Day 4 Homework - Karen.md new file mode 100644 index 0000000..9b803fe --- /dev/null +++ b/Day 4 Homework - Karen.md @@ -0,0 +1,173 @@ +``` +class Toaster: + def __init__(self): + self.ticks_left = 10 + self.is_on = False + + def get_uses(self): + return { + 'toast': "Put bread in the toaster to make toast." + } + + def start(self): + print("Toaster started.") + + def use(self, *args, **kwargs): + if 'toast' in args: + if not self.is_on: + print("Turn the toaster on first!🔌") + return True + + print("Toasting...") + self.ticks_left -= 1 + if self.ticks_left == 0: + print("Toasting complete! 🍞") + return False + + return True + + def tick(self): + return True + + def stop(self): + print("Toaster stopped. ⏸") +``` + +``` +class AdvancedToaster: + def __init__(self): + self.ticks_left = 10 + self.is_on = False + self.toastiness = 0 + self.bread_count = 0 + self.crumb_tray = [] + self.temperature = None + self.weight = 1.5 # kg + self.voltage = 120 # V + self.power = 750 # W + self.materials = ['stainless steel', 'plastic', 'copper'] + self.dimensions = {'length': 30, 'width': 20, 'height': 25} # cm + self.color = 'silver' + self.price = 50 # USD + + def get_uses(self): + return { + 'turn_on': "Turn on the toaster.", + 'turn_off': "Turn off the toaster.", + 'insert_bread': "Insert bread into the toaster.", + 'eject_bread': "Eject bread from the toaster.", + 'increase_toastiness': "Increase the level of toastiness.", + 'decrease_toastiness': "Decrease the level of toastiness.", + 'add_bread': "Add a slice of bread to the toaster.", + 'remove_bread': "Remove a slice of bread from the toaster.", + 'toast': "Toast the bread in the toaster.", + 'empty_crumb_tray': "Empty the crumb tray.", + 'weigh': "Weigh the toaster.", + 'measure_voltage': "Measure the voltage of the toaster.", + 'measure_power': "Measure the power of the toaster.", + 'get_materials': "Get the materials the toaster is made of.", + 'get_dimensions': "Get the dimensions of the toaster.", + 'get_color': "Get the color of the toaster.", + 'get_price_tag': "Get the estimated value of the toaster." + } + + def start(self): + print("Toaster started.") + + def set_temperature(self, temperature): + self.temperature = temperature + print(f"Toaster temperature set to {temperature} degrees Celsius.") + + def get_temperature(self): + if self.temperature is not None: + print(f"Toaster temperature is {self.temperature} degrees Celsius.") + else: + print("Toaster temperature has not been set yet.") + + def use(self, *args, **kwargs): + if 'turn_on' in args: + self.is_on = True + print("Toaster turned on.") + + elif 'turn_off' in args: + self.is_on = False + print("Toaster turned off.") + + elif 'insert_bread' in args: + if not self.is_on: + print("Turn the toaster on first!") + return True + + if self.bread_count > 2: + print("Too many bread slices! Maximum is 2.") + return True + + self.bread_count += 1 + print(f"{self.bread_count} bread slice{'s' if self.bread_count > 1 else ''} inserted.") + + elif 'eject_bread' in args: + if self.bread_count == 0: + print("No bread slices to eject.") + return True + + self.bread_count -= 1 + print("Bread slice ejected.") + + elif 'decrease_toastiness' in args: + if self.toastiness > 0: + self.toastiness -= 1 + print(f"Toastiness decreased to {self.toastiness}.") + + elif 'add_bread' in args: + if self.bread_count < 2: + self.bread_count += 1 + print(f"{self.bread_count} slice(s) of bread added to the toaster.") + + elif 'remove_bread' in args: + if self.bread_count > 0: + self.bread_count -= 1 + print(f"{self.bread_count} slice(s) of bread removed from the toaster.") + + elif 'toast' in args: + if self.is_on and self.bread_count > 0: + print("Toasting bread...") + for i in range(self.toastiness): + print("Tick...") + print("Bread toasted!") + self.bread_count -= 1 + elif not self.is_on: + print("Toaster is not turned on.") + elif self.bread_count == 0: + print("Toaster does not contain any bread.") + else: + print(f"DEBUG:Invalid use of the toaster.") + return False + + elif 'empty_crumb_tray' in args: + self.crumb_tray = [] + print("Crumb tray emptied.") + + def weigh(self): + print(f"The weight of the toaster is {self.weight} kg.") + + def measure_voltage(self): + # Method to measure the voltage of the toaster + print(f"The voltage of the toaster is {self.voltage} V.") + + def measure_power(self): + # Method to measure the power of the toaster + print(f"The power of the toaster is {self.power} W.") + + + defer get_materials(self): + print(f"The toaster is made of: {', '.join(self.materials)}.") + + defer get_dimensions(self): + print(f"The dimensions of the toaster are: {self.dimensions['length']} cm x {self.dimensions['width']} cm x {self.dimensions['height']} cm.") + + defer get_color(self): + print(f"The color of the toaster is {self.color}.") + + defer get_price_tag(self): + print(f"The estimated value of the toaster is {self.price_tag}.") +```