Guess the Number Game Code: Python Project for Kids
Source Code:
import random
def guessthenumber(): print("Welcome to Guess the Number!") number = random.randint(1, 20) attempts = 0 while True: guess = int(input("Guess a number between 1 and 20: ")) attempts += 1 if guess < number: print("Too low! Try again.") elif guess > number: print("Too high! Try again.") else: print(f"Congratulations! You guessed the number in {attempts} attempts.") break
Source Code:
import random
def guessthenumber():
print("Welcome to Guess the Number!")
number = random.randint(1, 20)
attempts = 0
while True:
guess = int(input("Guess a number between 1 and 20: "))
attempts += 1
if guess < number:
print("Too low! Try again.")
elif guess > number:
print("Too high! Try again.")
else:
print(f"Congratulations! You guessed the number in {attempts} attempts.")
break
guessthenumber()
For More Project Ideas Read: https://www.modernagecoders.com/blog/python-games-and-fun-projects-for-kids