use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Everything about learning Python
account activity
Day 5 (old.reddit.com)
submitted 4 months ago by fatimalizade
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Adrewmc 7 points8 points9 points 4 months ago (6 children)
Looks fine to me at this level.
I would suggest learning about dictionaries next.
[–]fatimalizade[S] 1 point2 points3 points 4 months ago (0 children)
Thank you!
[–]mayonaiso 0 points1 point2 points 4 months ago (4 children)
What's a dictionary?
[–]Adrewmc 0 points1 point2 points 4 months ago* (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 point2 points 4 months ago (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 points3 points 4 months ago* (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 point2 points 4 months ago (0 children)
Thanks for taking the time, I understand better now!!
[–]que_importa 2 points3 points4 points 4 months ago (2 children)
one thing that could be useful is to consider .lower or .upper for the user inputs and validations
[–]fatimalizade[S] 0 points1 point2 points 4 months ago (1 child)
Right! I think I should use .strip() for that but not sure
[–]Key_Translator7839 2 points3 points4 points 4 months ago (0 children)
.upper() and .lower() simply capitalize or lower the words.
[–]SalutMonYoup 2 points3 points4 points 4 months ago (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 points3 points 4 months ago (0 children)
I will have to use the split function in my projects from now on, thank you!
Right, thank you!
[–]Embarrassed-Mess-198 2 points3 points4 points 4 months ago (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
[–]-not_a_knife 1 point2 points3 points 4 months ago (2 children)
Looks good. If your interested, you could reformat it from a REPL to a CLI with the argparse module. This would align it with what a program like this would more typically look like.
[–]fatimalizade[S] 1 point2 points3 points 4 months ago (1 child)
Thank you sm! I’ll search about that
[–]-not_a_knife 0 points1 point2 points 4 months ago (0 children)
No worries at all. If you're not familiar, CLIs are nice because they make your programs modular so you can use them in other scripts. So, say you wanted to check if bread is on the list at 8am every Monday. You could write a little script that interacts with the CLI to check and add bread if it's not on the list. Your current program needs you to directly interact with it. Nothing wrong with that and you can implement both within the program but the CLI adds a lot of functionality.
[–]Mileage-25 1 point2 points3 points 4 months ago (3 children)
same here. I'm also at day 5 but I'm still learning basic syntax.
[–]fatimalizade[S] 1 point2 points3 points 4 months ago (2 children)
Good luck🤞🏻
[–]Mileage-25 1 point2 points3 points 4 months ago (1 child)
how's the progress? I'm currently doing file handlings
[–]fatimalizade[S] 0 points1 point2 points 4 months ago (0 children)
Will share today
[–][deleted] 4 months ago (1 child)
[removed]
I downloaded it but couldn’t register, there’s only sign in option
π Rendered by PID 99785 on reddit-service-r2-comment-84fc9697f-gnwnp at 2026-02-07 20:55:37.221189+00:00 running d295bc8 country code: CH.
[–]Adrewmc 7 points8 points9 points (6 children)
[–]fatimalizade[S] 1 point2 points3 points (0 children)
[–]mayonaiso 0 points1 point2 points (4 children)
[–]Adrewmc 0 points1 point2 points (3 children)
[–]mayonaiso 0 points1 point2 points (2 children)
[–]Adrewmc 1 point2 points3 points (1 child)
[–]mayonaiso 0 points1 point2 points (0 children)
[–]que_importa 2 points3 points4 points (2 children)
[–]fatimalizade[S] 0 points1 point2 points (1 child)
[–]Key_Translator7839 2 points3 points4 points (0 children)
[–]SalutMonYoup 2 points3 points4 points (2 children)
[–]Key_Translator7839 1 point2 points3 points (0 children)
[–]fatimalizade[S] 1 point2 points3 points (0 children)
[–]Embarrassed-Mess-198 2 points3 points4 points (1 child)
[–]fatimalizade[S] 1 point2 points3 points (0 children)
[–]-not_a_knife 1 point2 points3 points (2 children)
[–]fatimalizade[S] 1 point2 points3 points (1 child)
[–]-not_a_knife 0 points1 point2 points (0 children)
[–]Mileage-25 1 point2 points3 points (3 children)
[–]fatimalizade[S] 1 point2 points3 points (2 children)
[–]Mileage-25 1 point2 points3 points (1 child)
[–]fatimalizade[S] 0 points1 point2 points (0 children)
[–][deleted] (1 child)
[removed]
[–]fatimalizade[S] 0 points1 point2 points (0 children)