Skip to content

Instantly share code, notes, and snippets.

@darthShadow
Last active August 29, 2015 14:19
Show Gist options
  • Save darthShadow/0bd70448a1928b68624e to your computer and use it in GitHub Desktop.
Save darthShadow/0bd70448a1928b68624e to your computer and use it in GitHub Desktop.
# Author : Anagh Kumar Baranwal
# Question : http://www.practicepython.org/exercise/2014/04/02/09-guessing-game-one.html
import random
rand_num = random.randint(1,9)
count = 0
while(1):
choice = input("Please enter the number OR 'exit' to exit : ")
if(choice == "exit"):
print("You guessed "+str(count)+" times")
break
else:
num = int(choice)
if(num == rand_num):
print("Exactly Right")
elif(num > rand_num):
print("Too High")
count+=1
elif(num < rand_num):
print("Too Low")
count+=1
else:
print("Enter valid integer")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment