James
Active Coder
Okay, so in this tutorial, I will be going through the steps to create a guessing game in python 3.7
First, you will need to import the random module, this module is auto-installed along with python.
Second, we need to greet the user when they join
now we need to define a variables
This variable will track your points throughout the game.
Okay, so now we need to make the actual game, to do this and make the game go on forever we need to make a loop.
Now we need to ask a random question
Now let's see if they guessed right
Still, the game goes on forever so lets add a loosing.
To put it all together,
First, you will need to import the random module, this module is auto-installed along with python.
import random
Second, we need to greet the user when they join
Python:
print("""
Welcome to this guessing game in python!
Good luck!
""")
now we need to define a variables
Python:
points = 0
Okay, so now we need to make the actual game, to do this and make the game go on forever we need to make a loop.
Python:
while True:
pass
Python:
between = random.randint(10,25)
rn = random.randint(1,between)
question = input("I choose a number between 1 and "+str(between)+"\n>>> ")
Python:
if int(question) == between:
points += 1
Python:
else:
print("You lost!")
print("You got "+points+" points")
input(" ")
Python:
import random
points = 0
print("""
Welcome to this guessing game.
Good luck!
""")
while True:
between = random.randint(10,25)
rn = random.randint(1,between)
question = input("I choose a random number between 1 and "+str(between)+"\n>>> ")
if int(question) == rn:
points += 1
else:
print("You lost")
print("You got "+str(points)+" points!")
input(" ")
Last edited: