-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThird Challenge.py
More file actions
31 lines (24 loc) · 785 Bytes
/
Copy pathThird Challenge.py
File metadata and controls
31 lines (24 loc) · 785 Bytes
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
# Modify the program below to use a while loop to
# allow as many guesses as necessary.
#
# The program should let the player know whether to
# guess higher or lower, and should print a message
# when the guess is correct, A correct guess will
# terminate the if program.
#
# As an optional extra, allow the player to quit by entering
# 0 (zero) for their guess.
# This is a modified "Guess the number" game.
import random
highest = 100
answer = random.randint(1, highest)
guess = 0
print("Please guess a number between 1 and {}:".format(highest))
while guess != answer:
guess = int(input())
if guess < answer:
print("Please guess higher")
elif guess > answer:
print("Please guess lower")
else:
print("Well done, you guessed it")