DEV Community 👩‍💻👨‍💻

Discussion on: Solving the Problem Sets of CS50's Introduction to Programming with Python — One at a Time: Problem Set 3

 
rivea0 profile image
Eda Author

I implemented it with the same logic as well. But, you need to wrap everything inside a try...except block. Like, you can try to get the input and put it inside the dictionary; and only inside except EOFError you can do the for loop and printing. Also, I don't think you need to specify end inside the first print function and then print a newline. Just print(f"{value} {key.upper()})" will be going to provide a new line after each time by default, so you do not need to do anything else.

Thread Thread
 
heyandre profile image
Andre Castro

Ye I have everything wrapped inside try...except block, just didnt include that in the code I wrote here...

Thread Thread
 
heyandre profile image
Andre Castro • Edited on

Amazing! I fixed it! Thanks a lot for the tip...I was around and around trying new ways and would never have guessed that the for loop should be inside the except. I even tried import sys and use sys.stdin.read().split("\n") and was working as expected, but couldn't get green checks, only yellow checks ...anyway, now looking through the code and thinking about the logic makes perfect sense...Thanks a lot! Onto the next one :)

Thread Thread
 
rivea0 profile image
Eda Author

Congrats! We only need to print everything after the user hits control-d (resulting in EOFError), so it makes sense to put it inside the except. It's absolutely great to see that helped!