Guess the number game with Python code
import random
game="GUESS THE NUMBER GAME"
print(game.center(40))
print("---------------------------------------")
attempts = 0
x=random.randint(1,100)
while True:
guess=int(input("\n GUESS THE NUMBER BETWEEN 1 TO 100: "))
attempts+=1
if x<guess:
print("\nTRY LOWER NUMBER")
elif x>guess:
print("\nTRY HIGHER NUMBER")
else:
print(f"\n YOU GUESSED IT RIGHT IN {attempts} ATTEMPTS")
break
Comments
Post a Comment