a guest Nov 19th, 2019 83 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- # This is a guess the number game
- import random
- print 'Hello. What is your name?'
- name = raw_input()
- print 'Well ' + name + ', I am thinking of a number between 1 and 20.'
- secret_number = random.randint(1,20)
- for guesses_taken in range(7):
- print 'Take a guess.'
- guess = int(raw_input())
- except ValueError:
- print 'Please type a number for this game to work'
- if guess < secret_number:
- print 'Your guess is too low.'
- elif guess > secret_number:
- print 'Your guess is too high.'
- break # This condition is for the correct guess only
- if guess == secret_number:
- print 'Good job, ' + name + ' ! You guessed my number in ' + str(guesses_taken) + ' guesses'
- print 'Nope. The number I was thinking of was ' + str(secret_number)
- print 'You took ' + str(guesses_taken) + ' guesses.'
RAW Paste Data