PYTHON GUESSING GAME
This is a good game to aid the learning of Python loops, user input, error checking and if statements.
|
|
import random
num = random.randint(1,10)
guess = 0
score = 10
while guess != num:
try:
guess = int(input("Please enter a number between 1 and 10: "))
if guess > num:
print ("You guess too high")
score = score - 1
elif guess < num:
print ("You guess too low")
score = score - 1
except:
print ("You entered an invalid value")
print ("That is correct")
print ("Your score is: " + str(score))
Please feel free to copy and paste the code from above.