-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtesting.py
More file actions
71 lines (57 loc) · 2 KB
/
testing.py
File metadata and controls
71 lines (57 loc) · 2 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import random
# set high score
high_score = 10
def start_game():
# creating a function that asks for guesses while adding to trys
def prompter():
nonlocal trys
trys += 1
return input("Choose a number from 1 - 10\n")
# declairing game var
trys = 0
answer = random.randint(1, 10)
# declairing guess so fails first loop
guess = 0
# while loop that ends when player answers correct number
while guess != answer:
# prompting palyer for a guess
guess = prompter()
# while loop making sure that the number entered is a valid number
while type(guess) != int:
try:
guess = int(guess)
except ValueError:
print("Please enter a valid number")
guess = prompter()
# letting user know if they guessed higher or lowwer than answer and checking if guess is within the range(1 - 10)
if guess < 1 or guess > 10:
print("number was not between 1 and 10")
guess = prompter()
elif guess < answer:
print("Higher")
elif guess > answer:
print("Lowwer")
# after loop let player know how many tries it took them to get the correct answer and if they got the high score
print(f"you got it in {trys} try(s)")
global high_score
if high_score > trys:
high_score = trys
print(f"Wow!!! you just made the high score")
elif high_score < trys:
print(f"so close the high score was {high_score}, you were just {trys - high_score} away from breaking the record")
else:
print("you tied the high score")
start_game()
# function that answers if player would like to play again
def replay():
replay = input("would you like to play again?\n(yes/no) ")
if replay == "yes":
return True
else:
return False
again = replay()
# loop enabling multiple games
while again:
start_game()
again = replay()
print("Hate to see you leave, Goodbye!")