Quick actions

cmd+k|ctrl+k

Navigation

Languages

Guessing game

Snippet info

Language

Python

Visibility

public

Author

bensruthy

Created

2026-04-01T05:48:57.612513Z

Updated

2026-04-01T05:48:57.612513Z

# create a random number between 1 to 10
#input a number
#check the number if between 1 to 10
#if both number are same then you got it correct else try again


from random import randint

answer= randint(1,10)
#print (answer)

while (True):
    
    guess= int(input("Enter a number between 1 to 10: "))
    try:
        
        if (0<guess<11):
            if (guess==answer):
                print("you got it right")
                break
        else:
            print("Enter a number between 1 and 10")
            
    except ValueError:
        print("enter a number")
        continue
INFO