Advertisement
Sparkster

Untitled

Jul 21st, 2013
330
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.     tries = 0
  9.     guess = 1
  10.     while guess != number:
  11.         guess = raw_input("Guess a number between 1 and 100: ")
  12.         if guess < number:
  13.             print "Guess higher!"
  14.             tries += 1
  15.         elif guess > number:
  16.             print "Guess lower!"
  17.             tries += 1
  18.         else:
  19.             print "You have won!"
  20.             tries += 1
  21.             print "It took you %d tries!" % tries
  22.  
  23. print findnumber()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement