Guess the number mini game code in python
# Mini game
import random
def play_game():
secret_num = random.randint(1, 10)
attempts = 0
while True:
guess = int(input("Guess a number between 1 and 10: "))
attempts += 1
if guess == secret_num:
print(f"Congratulations! You guessed the number in {attempts} attempts.")
break
elif guess < secret_num:
print("Too low, try again!")
else:
print("Too high, try again!")
play_game()
# Mini game
import random
def play_game():
secret_num = random.randint(1, 10)
attempts = 0
while True:
guess = int(input("Guess a number between 1 and 10: "))
attempts += 1
if guess == secret_num:
print(f"Congratulations! You guessed the number in {attempts} attempts.")
break
elif guess < secret_num:
print("Too low, try again!")
else:
print("Too high, try again!")
play_game()