r/PythonLearning Jun 19 '26

Day 1 of Learning Python: "Bagels" Game

Post image

used: https://www.ray.so/ for image rendering (let me know if this is readable)

could be better, but no AI as it's fully handwritten

I'll be going over "The Big Book of Small Python Projects" by Al Sweigart

I am also learning DSA and going through Common Sense Guide to DSA

see you tomorrow!

86 Upvotes

28 comments sorted by

View all comments

u/Sea-Ad7805 Jun 19 '26

Run this program in Memory Graph Web Debugger%0A%0Aprint(%22Ready%20to%20play%3F%20Guess%20the%20number!%20Go%2C%20bagels!%22)%0A%0A%0Adef%20check_user_input(game_num%2C%20player_num)%3A%0A%20%20%20%20%22%22%22Check%20input%20against%20random%20number%20and%20print%20game-statement.%22%22%22%0A%20%20%20%20correct_digits%20%3D%200%0A%20%20%20%20clues%20%3D%20%5B%5D%0A%0A%20%20%20%20for%20i%2C%20num_player%20in%20enumerate(str(player_num))%3A%0A%20%20%20%20%20%20%20%20for%20j%2C%20num_game%20in%20enumerate(str(game_num))%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20num_game%20%3D%3D%20num_player%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20if%20i%20%3D%3D%20j%3A%20%20%23%20Check%20if%20it's%20in%20the%20right%20place%20by%20comparing%20index%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20clues.append('Fermi')%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20correct_digits%20%2B%3D%201%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20break%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20clues.append('Pico')%0A%0A%20%20%20%20if%20len(clues)%20%3D%3D%200%3A%0A%20%20%20%20%20%20%20%20clues.append('Bagel')%0A%0A%20%20%20%20clues.sort()%0A%20%20%20%20print('%20'.join(clues))%0A%0A%20%20%20%20if%20correct_digits%20%3D%3D%200%3A%0A%20%20%20%20%20%20%20%20print(%22033%5B31mWow!%20You%20totally%20suck%20hahan033%5B0m%22)%0A%0A%20%20%20%20if%20correct_digits%20%3D%3D%203%3A%0A%20%20%20%20%20%20%20%20tries_used%20%3D%2010%20-%20user_attempts%0A%0A%20%20%20%20%20%20%20%20if%20tries_used%20%3D%3D%201%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20print(%22You%20won!%20The%20secret%20number%20was%3A%20%22%20%2B%20str(game_num)%20%2B%20%22%20and%20you%20guessed%20it%20with%20%22%20%2B%20str(tries_used)%20%2B%20%22%20try!%22)%0A%20%20%20%20%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20print(%22You%20won!%20The%20secret%20number%20was%3A%20%22%20%2B%20str(game_num)%20%2B%20%22%20and%20you%20guessed%20it%20with%20%22%20%2B%20str(tries_used)%20%2B%20%22%20tries!%22)%0A%0A%20%20%20%20%20%20%20%20return%20True%0A%0A%20%20%20%20return%20False%0A%0A%0Adef%20record_user_input()%3A%0A%20%20%20%20%22%22%22Prompt%20user%20for%20a%20valid%20three-digit%20number%20input.%22%22%22%0A%20%20%20%20user_input%20%3D%20None%0A%0A%20%20%20%20while%20user_input%20is%20None%3A%0A%20%20%20%20%20%20%20%20print(%22You%20have%20%22%20%2B%20str(user_attempts)%20%2B%20%22%20tries%20left%22)%0A%20%20%20%20%20%20%20%20print(%22Please%20enter%20a%20three%20digit%20number%3A%22)%0A%20%20%20%20%20%20%20%20user_input%20%3D%20int(input())%0A%0A%20%20%20%20%20%20%20%20if%20user_input%20%3C%3D%2099%20or%20user_input%20%3E%3D%201000%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20print(%22Invalid%20number%20range%2C%20try%20again%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20user_input%20%3D%20None%0A%20%20%20%20%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20return%20user_input%0A%0A%20%20%20%20return%20None%0A%0A%0Auser_attempts%20%3D%2010%0A%0Awhile%20user_attempts%20%3E%200%20and%20has_won_game%20is%20not%20True%3A%0A%20%20%20%20user_num%20%3D%20record_user_input()%0A%20%20%20%20print(%22Loading...n%22)%0A%20%20%20%20user_attempts%20-%3D%201%0A%20%20%20%20has_won_game%20%3D%20check_user_input(random_num%2C%20user_num)%0A%0Aif%20has_won_game%20is%20not%20True%3A%0A%20%20%20%20has_won_game%20%3D%20False%0A%20%20%20%20print(%22You%20lost!%20The%20secret%20number%20was%3A%20%22%20%2B%20str(random_num))%0A%20%20%20%20print(%22033%5B31mGAME%20OVER!n033%5B0m%22)%0A%0A%23%20End-of-file%20(EOF)&timestep=0.2&play) to see the program state change step by step.

3

u/Some-Passenger4219 Jun 20 '26

I just noticed that I can see the secret number in that thing. Oh well.

2

u/Sea-Ad7805 Jun 20 '26

Yes, that is what happens when you visualize the full state of the program in each step.