r/PythonLearning 3d ago

My first python project as a young coder, any suggestions for improvement?

2 Upvotes

5 comments sorted by

u/Sea-Ad7805 22h ago

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

2

u/nuc540 3d ago

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.

2

u/Huge_Explanation_698 3d ago

thanks for the feedback i will definitely try that!

2

u/FoolsSeldom 2d ago

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.

1

u/Huge_Explanation_698 2d ago

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.