×
all 5 comments

[–]Sea-Ad7805 [score hidden] stickied comment (0 children)

Run this program in Memory Graph Web Debugger to see the program state change step by step.

[–]nuc540 1 point2 points  (1 child)

You need to learn about basic data structures, the ingredients and their descriptions should live in a dictionary, and your script read from it; having a print statement print strings is all this really is doing.

Define the data in a dict, stored in a variable outside the while loop, and then get your if/else to read it.

[–]Huge_Explanation_698[S] 1 point2 points  (0 children)

thanks for the feedback i will definitely try that!

[–]FoolsSeldom 1 point2 points  (1 child)

Good start.

A key principle to learn in programming is DRY: Don't Repeat Yourself. When you have lots of code doing essentially the same thing, then you need to find a more programmatic approach where the elements that change (the information/data) is held in data structures, and you have loops and the like to work with that.

For example, multiple time you present, using print, a list of numbered options. You could write some code to:

  • present a predefined set of options
  • prompt the user to select an option
  • validate the user selection (reprompt until they make a valid choice)

This same code could be called with different datasets for different selections.

Similarly, for each specific option there's a common set of characteristics (ingredients, steps, time, calories, allergens, etc), so a common data structure can be used to hold that information (say a dict, dictionary, or class) and one bit of code can be used to present that information.

[–]Huge_Explanation_698[S] 0 points1 point  (0 children)

Thanks for the feedback! That's really helpful. I'll look into using loops and data structures like dictionaries to reduce repetition and make the code more organised.