Advertisement
Guest User

Python Challenge Madlibs

a guest
Mar 26th, 2013
622
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.96 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on Tue Mar 26 10:39:40 2013
  4.  
  5. @author: casa
  6. """
  7. import random
  8. print "In this game the system takes a random number between 1 and 6 (including) and you need to guess it. If you guess right you win. Your score depends on how many times you needed tyo guess before getting it right. If you are tired you can give up by typing 'done'.\n"
  9. name = raw_input("What is your name?")
  10. random_number = random.randint(1,6)
  11. count = 0
  12. while (True) :
  13.     input = raw_input('Enter a number: ')
  14.     if input == 'done' :
  15.         print("Thank you for playing, %s.") % name        
  16.         break
  17.     try :
  18.         input = int(input)
  19.     except :
  20.         print("Wrong! Only numbers are allowed!")
  21.         continue
  22.     count = count + 1
  23.     if input not in range(6) : print("Wrong! You should enter a number between 1 and 6.")
  24.     if input == random_number :
  25.         print("Congratulations %s, you win in %d guesses!") % (name, count)
  26.         exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement