-
Notifications
You must be signed in to change notification settings - Fork 0
/
HackbrightChallenge.py
44 lines (32 loc) · 1.12 KB
/
HackbrightChallenge.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
38
39
40
41
42
43
44
import random
# function definition
def guess_game():
# define random number
randNum = random.randrange(1,100)
#set counter for guesses = 0
guessCount = 0
gameEval = False
guessList = []
while gameEval == False:
# while guess != random number, ask user for a guess
guess = int(input("Please enter a number between 1 and 100."))
if guessCount > 0:
# while unique = False, ask user for a new guess
while guess in guessList:
guess = int(input("Enter a unique guess between 1 and 100."))
# store unique guess in guessList
guessList.append(guess)
# increment guess counter
guessCount += 1
# evaluate guess
if guess > randNum:
print("Your guess is too high. Try again!")
if guess < randNum:
print("Your guess is too low. Try again!")
if guess == randNum:
gameEval = True
# end of game
print("Correct! The number I was thinking of was",randNum,".")
print("It took you",guessCount,"guesses.")
return
guess_game()