Python - 16

Python - 16: Random Numbers & Simple Games

Python can generate random numbers to make games and interactive programs.

✦ Python Editor
▶ Output

👀 Show Example Solution
import random

dice = random.randint(1, 6)

print("Dice Roll:")
print(dice)

secret = random.randint(1, 3)

guess = input("Pick a number from 1 to 3: ")

if int(guess) == secret:
    print("You win!")

else:
    print("Try again!")
    print("Secret number:")
    print(secret)