Oct-09-2019, 10:22 AM
I am new to Python and programming in general. I am just learning how to use functions.
I made a Fridge script, where it asks a user to input different kinds of food items, adds them to a food category, and then moves on to the next category. At the end it lists everything they've added to the fridge by category. Here is an example of one function:
Also, I tried to make a Fridge Class, in case a user may have multiple fridges, but I'm having trouble getting the arguments to be correct, and gave up on it and just made it using functions. If anyone can suggest how to make this Class-based, I would appreciate that as well.
This link goes to the entire thing:
https://pastebin.com/LL0x31AS
I made a Fridge script, where it asks a user to input different kinds of food items, adds them to a food category, and then moves on to the next category. At the end it lists everything they've added to the fridge by category. Here is an example of one function:
def add_fruit_fridge(): """Puts fruit in the fridge until user terminates loop.""" while True: print("\n:::What fruits do you want to add?::: ") fruits.append(input("\n")) answer = input("Anything else? Please enter Y or N: ") if answer == 'Y': print("\n") elif answer == 'N': break else: breakI am using a different function for each type of food. The script comes out to over 100 lines long, and I realize it is very inefficient. My question is, how can I refactor this script so it uses only one, or less functions to achieve the same result?
Also, I tried to make a Fridge Class, in case a user may have multiple fridges, but I'm having trouble getting the arguments to be correct, and gave up on it and just made it using functions. If anyone can suggest how to make this Class-based, I would appreciate that as well.
This link goes to the entire thing:
https://pastebin.com/LL0x31AS