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
secret = random.randint(1, 50)
print("Guess my number from 1 to 50. You have 7 tries.")
for attempt in range(7):
guess = int(input("Guess: "))
if guess == secret:
print("You got it!")
break
if guess < secret:
print("Too low")
else:
print("Too high")
else:
print("You lose. The number was", secret)