python text game
Python hosting: Host, run, and code Python in the cloud!
In this article we will demonstrate how to create a simple guessing game.
The goal of the game is to guess the right number.
Example
An example run below:
You may like
Simple games with Python
Random number
The user will be asked to guess the random number. We first pick the random number:
from random import randint |
The randint() function will pick a pseudo random number between 1 and 10. Then we have to continue until the correct number is found:
guess = -1 |
Python Guessing Game
The code below starts the game:
from random import randint |
An example run:
Guess the number below 10: |
You may like
Simple games with Python
Leave a Reply:
How do you print a random float?
Hi Nathan,
You can get a random float using the random.uniform() function.
Example program generating a float between 1.1 and 5.5:
How do I play the game
Execute it with Python. (python game.py), where game.py is one of the files above