Python Projects & Skills / Games
Lesson 6 of 28
Number guessing game
Pick a random number and let the player guess with 'higher' or 'lower' hints. It practises loops, input, conditions and random.
Key points
- random.randint(1, 100)
- Loop until correct
- Count the guesses
import random
secret = random.randint(1, 100)
while (g := int(input("Guess: "))) != secret:
print("Higher" if g < secret else "Lower")
print("Got it!")Quiz · +10 XP
Which function picks a random whole number between two values?
Log in to save progress and earn XP.