Advertisement
Sparkster

Untitled

Jul 21st, 2013
325
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Simple guess the number game
  2.  
  3. from random import randint
  4.  
  5. def findnumber():
  6.     number = randint(1,100)
  7.     print number
  8.     guess = raw_input("Guess a number between 1 and 100: ")
  9.     tries = 0
  10.     while guess != number:
  11.         if not guess.isalpha():
  12.             print "That is not a number!"
  13.         elif guess < number:
  14.             print "Guess higher!"
  15.             tries += 1
  16.         elif guess > number:
  17.             print "Guess lower!"
  18.             tries += 1
  19.             findnumber()
  20.         else:
  21.             print "You have won!"
  22.             tries += 1
  23.             print "It took you %d tries!" % tries
  24.  
  25. print findnumber()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement