-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame.py
55 lines (45 loc) · 1.57 KB
/
game.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
45
46
47
48
49
50
51
52
53
54
55
import random
guessed_nums = []
allowed_guesses = 0
difficulty = 0
#Difficulty Selection
while True:
selection = input("Select EASY/MEDIUM/HARD: ")
if selection == "EASY":
print("You have 6 guesses")
allowed_guesses = 6
difficulty = 10
break
if selection == "MEDIUM":
print("You have 4 guesses")
allowed_guesses = 4
difficulty = 20
else:
if selection == "HARD":
print("You have 3 guesses")
allowed_guesses = 3
difficulty = 50
break
rand_num = random.randint(1, difficulty)
while len(guessed_nums) < allowed_guesses:
#make sure this section updates based on difficulty selection.
guess = input("Guess a number between 1 and {}. \n".format(difficulty)) #user guesses number
try:
player_num = int(guess)
except:
print("That's not a whole number!")
break
#mthis section updates based on difficulty selection.
if not player_num > 0 or not player_num <= difficulty:
print("Please guess a number between 1 and {}".format(difficulty))
continue
guessed_nums.append(player_num)
if player_num == rand_num:
print("You got it right!".format(rand_num))
print("It took you {} tries.".format(len(guessed_nums)))
break
else:
print("That was wrong. Guess #{}".format(len(guessed_nums)))
continue
if not rand_num in guessed_nums:
print("Game over! My number was {}".format(rand_num))