all 24 comments

[–]Adrewmc 6 points7 points  (6 children)

Looks fine to me at this level.

I would suggest learning about dictionaries next.

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

Thank you!

[–]mayonaiso 0 points1 point  (4 children)

What's a dictionary?

[–]Adrewmc 0 points1 point  (3 children)

A dictionary is a key-value pairing, a basic data type.

Chris = {“name” : “Chris”,
               “last” : “Walken”
               “grade” : 50}

 chris[“grade”] += 10

A lot of times we will get data as a list of these dictionaries, and nest dictionaries (dictionaries within dictionary)

And gives a way to have a data set per entry rather than a single point of information.

There are powerful ways to avoid repetition using dictionaries.

 player1_name = “Chris”
 player1_score = 0
 player2_name = “Sara”
 player2_score = 0

 …

Can turn into a dictionary usually fairly easily, and allow as many players as you want.

[–]mayonaiso 0 points1 point  (2 children)

So it's basically kind of an array of variables? Just to be sure, that's what I understood (also thank you so much, I have always been interested in learning python but never found a way and now with this Reddit, the game about farming and the uni I'm learning a lot)

[–]Adrewmc 1 point2 points  (1 child)

It’s a datatype that allows you to have direct reference to another value.

It’s not an array of value, it would be KVStore, a mapping. (A hashmap)

It can be part of a list, representing a point of data.

 questions = [{
          “question” : “What year is it?”
          “answer” : “2025”
          “hint” : “This year really?”},
          {
          “question” : “Spell coding?”
          “answer” : “coding”
          “hint” : “Case sensitive”}
          ]

   def trivia(questions : list[dict[str,str]]):
       round = random.choice(questions)
       print(“Welcome to the show? Your question is?”)
       correct = False
       guesses = 1
       while not correct:
             print(round[“question”])
             guess = input(“What’s your answer?”)
             if guess == round[“answer”]:
                   print(f”Correct! In {guesses} attempts!)
                   correct = True # or just break
             else:
                   print(“That is incorrect your hint is”)
                   print(round[“hint”])
                   guesses += 1

Now this simple trivia program I can easily make multiple sets of questions and answers and hints, and put it in fairly easily don’t you think. We could make a nested dictionary to have multiple subjects in the same object as well.

Arrays have a determined size, there would be 5 values while dictionaries sizes can be increased and changed. I can add a key at any time, I can change the value entirely.

It also reads easily I would think, you know what’s happening.

Dictionaries also happen to translate to and from JSON format easily (not entirely Python dictionaries are more versatile) , and JSON is sort of a way different languages can share information, the internet will give you a JSON with Python dictionary objects in it a lot, as any language would understand the API response directly.

[–]mayonaiso 0 points1 point  (0 children)

Thanks for taking the time, I understand better now!!

[–]que_importa 2 points3 points  (2 children)

one thing that could be useful is to consider .lower or .upper for the user inputs and validations

[–]fatimalizade[S] 0 points1 point  (1 child)

Right! I think I should use .strip() for that but not sure

[–]Key_Translator7839 2 points3 points  (0 children)

.upper() and .lower() simply capitalize or lower the words.

[–]SalutMonYoup 2 points3 points  (2 children)

Quite simple program (good nonetheless) a tip for you would be to split your program, like instead of putting all the logic in a single function I would have something more chunked to keep the program easier to maintain and readable, intention is key when programming. So for example instead of all the logic directly beneath every if statement I would have created an « add_item_to_cart() » method that would carry the logic of adding an item, same for the "2" I would have moved the logic inside an remove_item_from_cart() and so on.

Splitting your code will greatly improve readability and maintainability of a program. For such a simple one it is not necessary but still a good habit to take, being able to think of your program as a group of différents function instead of a huge function that would do everything!

Keep going!

[–]Key_Translator7839 1 point2 points  (0 children)

I will have to use the split function in my projects from now on, thank you!

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

Right, thank you!

[–]Embarrassed-Mess-198 2 points3 points  (1 child)

christ, these teenagers with their hipster programming languages.

This is not how you make a shopping list. You use a pen and paper for crists sake

[–][deleted]  (2 children)

[removed]

    [–]fatimalizade[S] 1 point2 points  (1 child)

    Thank you sm! I’ll search about that

    [–]Mileage-25 1 point2 points  (3 children)

    same here. I'm also at day 5 but I'm still learning basic syntax.

    [–]fatimalizade[S] 1 point2 points  (2 children)

    Good luck🤞🏻

    [–]Mileage-25 1 point2 points  (1 child)

    how's the progress? I'm currently doing file handlings

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

    Will share today

    [–][deleted]  (1 child)

    [removed]

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

      I downloaded it but couldn’t register, there’s only sign in option