Advertisement
zenware

Python Guessing Game

Oct 20th, 2011
393
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.87 KB | None | 0 0
  1. import random
  2. import string
  3. def guess(start=1, stop=100, tries=6):
  4.     randNum = random.randrange(start, stop)
  5.     count = 0
  6.     print("I've picked a number between ",start," and ",stop)
  7.     print("You have",tries,"tries to guess.")
  8.     print("Can you guess it?")
  9.     while count != tries:
  10.         count = count+1
  11.         guessNum = input('Guess: ')
  12.         if str.lower(guessNum) in string.ascii_lowercase:
  13.             count = count-1
  14.             print("That's not a number, don't worry, it doesn't count!")
  15.         elif int(guessNum) not in range(start, stop+1):
  16.             count = count-1
  17.             print("You guessed a number out of range, don't worry, it doesn't count!")
  18.         elif int(guessNum) > randNum and int(guessNum) in range(start, stop):
  19.             print("Guess Lower!")
  20.         elif int(guessNum) < randNum and int(guessNum) in range(start, stop):
  21.             print("Guess Higher!")
  22.         else:
  23.             print("Congrats! You guessed it in",count,"tries!")
  24.             break
  25.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement