Knowledge organisersRandom Number Generation
Use random in game logic.
Random numbers are essential in games for dice rolls, card shuffling, enemy spawning, and guessing games. Combine random.randint() with loops and selection for game logic.
random.randint(1, 6)import random
secret = random.randint(1, 100)
guess = 0
while guess != secret:
guess = int(input("Guess (1-100): "))
if guess < secret:
print("Higher!")
elif guess > secret:
print("Lower!")
print("Correct!")