Learn to code with step-by-step lessons. A place for students to work through programming fundamentals and build skills.
One possible program:
import random
play_again = "y"
while play_again.lower() == "y":
secret = random.randint(1, 20)
print("New game! 1-20.")
while True:
player_guess = int(input("Guess: "))
if player_guess < secret:
print("Too low")
elif player_guess > secret:
print("Too high")
else:
print("Got it!")
break
play_again = input("Play again? (y/n): ")