-
Notifications
You must be signed in to change notification settings - Fork 0
/
guess.py
37 lines (24 loc) · 919 Bytes
/
guess.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# This is a guess the number game.
import random
guessesTaken = 0
print('Hello! What is your name?')
myName = input()
number = random.randint(1,80)
print('Well, ' + myName + ' I am thinking of a number between 1 and 50.')
while guessesTaken < 4:
print('Take a guess.') # There are four spaces in front of print.
guess = input()
guess = int(guess)
guessesTaken=guessesTaken+1
if guess < number:
print('Your guess is too low.') # There are eight spaces in front of print.
if guess > number:
print('Your guess is too high.')
if guess == number:
break
if guess==number:
guessesTaken=str(guessesTaken)
print('Good job, '+ myName + '! You guessed my number in ' + guessesTaken + ' guesses!')
if guess != number:
number=str(number)
print('Nope. The number I was thinking of was ' + number)