-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathguess number game.py
78 lines (65 loc) · 2.05 KB
/
guess number 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import random
number_list = []
for i in range(0, 101):
number_list.append(i)
number = random.choice(number_list)
print(number)
print(f'''Welcome to the Number Guessing Game!
I'm thinking of a number between {min(number_list)} and {max(number_list)}''')
level = input("\nChoose a difficulty level. Type 'easy' or 'hard'\n").lower()
def get_level():
global attempts
level_stop = True
while level_stop:
new_level = input("type 'easy' or 'hard'\n").lower()
if new_level == "easy":
print("You have 5 guesses")
attempts += 5
level_stop = False
elif new_level == "hard":
print("You hve 3 guesses")
attempts += 3
level_stop = False
def compare():
global attempts
attempts -= 1
if int(user_guess) > max(number_list) or int(user_guess) < min(number_list):
print(f"enter value between {min(number_list)} and {max(number_list)}")
attempts += 1
elif int(user_guess) < number:
print("Your guess is too low")
elif int(user_guess) > number:
print("Your guess is too high")
else:
print('''You guessed the correct number
YOU WIN !!!''')
return True
def take_integer():
ask_again = True
while ask_again:
new_user_guess = input("Enter only integer value:")
for k in new_user_guess:
if k.isdecimal():
return new_user_guess
attempts = 0
if level == "easy":
attempts += 5
print(f"You have {attempts} guesses")
elif level == "hard":
attempts += 3
print(f"You hve {attempts} guesses")
else:
get_level()
exit_game = False
while not exit_game:
user_guess = input("Enter your guess: ")
for i in user_guess:
if i.isdecimal():
continue
else:
user_guess = take_integer()
exit_game = compare()
if attempts == 0:
print(f'''\nYour ran out of your attempts
the correct number was {number}''')
break