r/PythonLearning • u/Alireza7074 • Sep 25 '26
A easy code to create a Console python game
If you know python language you can develop that code!
2
u/Alireza7074 Sep 25 '26
Yeah for that you can use else in for to print some thing
1
u/Sea-Ad7805 Sep 26 '26 edited Sep 26 '26
Yes, you are correct, much cleaner with
elsewhen theforloop ends naturally instead of breaking: https://memory-graph.com/#code=%0Adef%20randomnum()%3A%0A%20%20%20%20a%20%3D%20input(%22please%20enter%20a%20number%3F%22)%0A%20%20%20%20b%20%3D%20%2223%22%0A%20%20%20%20if%20a%20%3D%3D%20b%3A%0A%20%20%20%20%20%20%20%20print(%22correct%22)%0A%20%20%20%20%20%20%20%20return%20True%0A%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20print(%22wrong%22)%0A%20%20%20%20return%20False%20%20%20%0A%0An%20%3D%2010%0Afor%20i%20in%20range(n)%3A%0A%20%20%20%20print(f'attempt%7Bi%2B1%7D%2F%7Bn%7D%3A%20'%2C%20end%3D'')%0A%20%20%20%20if%20randomnum()%3A%0A%20%20%20%20%20%20%20%20print(%22Done%2C%20thank%20for%20playing!%22)%0A%20%20%20%20%20%20%20%20break%0Aelse%3A%0A%20%20%20%20print(%22Sorry%20you%20failed.%22)%0A%20%20%20%20%0A×tep=0.2&play
1
1
1
•
u/Sea-Ad7805 Sep 25 '26 edited Sep 25 '26
Run and develop this program by clicking Memory Graph Web Debugger and see its state change step by step.
Why don't you stop the program after the user guesses correctly?
After you develop this code click 'Get URL' and post the url in the comments.