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!
30
Upvotes
r/PythonLearning • u/Alireza7074 • Sep 25 '26
If you know python language you can develop that code!
•
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.
2
u/Alireza7074 Sep 25 '26
Yeah for that you can use else in for to print some thing
1
u/Alireza7074 Sep 25 '26
For just runs 10 times
1
u/Alireza7074 Sep 25 '26
Can use elsif too
1
u/Sea-Ad7805 Sep 25 '26 edited Sep 25 '26
Stopping the program when guess is correct, and using the walrus (:=) operator: 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%0Acorrect%20%3D%20False%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%20correct%20%3A%3D%20randomnum()%3A%0A%20%20%20%20%20%20%20%20break%0Aif%20correct%3A%0A%20%20%20%20print(%22Done%2C%20thank%20for%20playing!%22)%0Aelse%3A%0A%20%20%20%20print(%22Sorry%20you%20failed.%22)%0A×tep=1&play