-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNumberGuess.py
More file actions
23 lines (21 loc) · 854 Bytes
/
NumberGuess.py
File metadata and controls
23 lines (21 loc) · 854 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import random
# a Broken but working number guessing game, Whats the error I think is the first print line using ` not ', why?
guessesUsed = 0
Name=input('Hello! What is your name? ')
number = random.randint(1, 30)
print('Greetings, ` + Name + `, I\`m thinking of a number between 1 and 30.')
while guessesUsed < 5:
guess=int(input('Guess the number withen 5 guesses...'))
guessesUsed = guessesUsed + 1
if guess < number:
print('Too low, try again.')
if guess > number:
print('Too high, try again.')
if guess == number:
break
if guess == number:
guessesUsed = str(guessesUsed)
print('Well done, ' + Name + '! You guessed correctly in ' + guessesUsed + 'guesses.')
if guess != number:
number = str(number)
print('Sorry, out of guesses. The number I was thinking of is ' + number)