Skip to content

Instantly share code, notes, and snippets.

@amankharwal
Created December 4, 2020 08:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amankharwal/89aafa805ead7b24e0ebed7d6054d331 to your computer and use it in GitHub Desktop.
Save amankharwal/89aafa805ead7b24e0ebed7d6054d331 to your computer and use it in GitHub Desktop.
# to import random module
import random
# to create a range of random numbers between 1-10
n = random.randrange(1,100)
# to take a user input to enter a number
guess = int(input("Enter any number: "))
while n!= guess: # means if n is not equal to the input guess
# if guess is smaller than n
if guess < n:
print("Too low")
# to again ask for input
guess = int(input("Enter number again: "))
# if guess is greater than n
elif guess > n:
print("Too high!")
# to again ask for the user input
guess = int(input("Enter number again: "))
# if guess gets equals to n terminate the while loop
else:
break
print("you guessed it right!!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment