Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- """
- Created on Tue Mar 26 10:39:40 2013
- @author: casa
- """
- import random
- 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"
- name = raw_input("What is your name?")
- random_number = random.randint(1,6)
- count = 0
- while (True) :
- input = raw_input('Enter a number: ')
- if input == 'done' :
- print("Thank you for playing, %s.") % name
- break
- try :
- input = int(input)
- except :
- print("Wrong! Only numbers are allowed!")
- continue
- count = count + 1
- if input not in range(6) : print("Wrong! You should enter a number between 1 and 6.")
- if input == random_number :
- print("Congratulations %s, you win in %d guesses!") % (name, count)
- exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement