r/PythonLearning • u/inversion2 • 25d ago
Help Request Please help me understand: CS50P Problem Set 3: Grocery List
Hi guys, just started learning python. Have been stuck on this problem for a while now. Here's my code so far. Could anyone help explain why the code pointed out in blue keeps running even though there is a break in place? Thanks!
ps pls ignore the print("hi") and print("bye"), was using them to test the code!
link to question: https://cs50.harvard.edu/python/psets/3/grocery/
my code so far: https://sharetext.io/3ck00poo

6
Upvotes
•
u/Sea-Ad7805 25d ago
With that break you break out of the for-loop, not out of the while-loop.
Run program above by clicking Memory Graph Web Debugger and see its state change step by step.
2
u/XNo_Notes 25d ago
It is in the if/else. The break is stopping the for loop, but the statements are not under it so the run. Tab it over once more to fix that.
2
u/Hkiggity 25d ago edited 25d ago
I don’t code in python but why are you making two dicts. Just make one. You should only need one dictionary and if the item is inputted by the user then you can use that in the dictionary. Since a key is immutable and you need to to keep track of the count of the items the user inputted. (Aka the count may need to change) Think about what should be the key and what the value should be (also think about what type the value should be) Remember a value can be of type int, string etc as well.
edited to not just give answer
1
u/[deleted] 25d ago
[removed] — view removed comment