Guessing the System generated number

import random

top=int(input("Enter the top number"))

ran=random.randrange(0,top)

print("Guess a number between 1 to",top-1)

guess=0
while True:
    guess+=1
    n=int(input("Make a guess"))
    if n==ran:
        print("You got it!")
        break
    else:
        print("You got it wrong!")

print("You got it in",guess,"guesses")

ShareSkills: Computer Knowledge

Design a site like this with WordPress.com
Get started