-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGuessingNumber.py
More file actions
66 lines (49 loc) · 1.37 KB
/
Copy pathGuessingNumber.py
File metadata and controls
66 lines (49 loc) · 1.37 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
#!/usr/bin/env python
# coding: utf-8
# In[ ]:
import random
attempts = 0
your_guess = 0
def levelChoice():
global attempts
level = input("Choose between 'Hard' or 'Easy': ").lower()
if level == "hard":
attempts = 5
else:
attempts = 10
def GuessesComparison():
global attempts, your_guess
number_list = list(range(1, 101))
guess = random.choice(number_list)
your_guess = int(input("Type Your Guess: "))
if guess == your_guess:
print(f"{your_guess} is the right one")
attempts -= 1
attempts = 0 # End the game when the guess is correct
elif guess > your_guess:
print(f"{your_guess} is too low")
attempts -= 1
elif guess < your_guess:
print(f"{your_guess} is too high")
attempts -= 1
else:
print(f"{your_guess} is out of scope")
attempts -= 1
def start():
print("Welcome to GuessingNumber")
print("You can guess between 1 and 100")
input("Type any key to proceed: ")
levelChoice()
start()
while attempts != 0:
GuessesComparison()
print(f"Attempts remaining: {attempts}")
choice = input("Do you want to start? 'Yes' or 'No': ").lower()
if choice == "yes":
start()
while attempts != 0:
GuessesComparison()
print(f"Attempts remaining: {attempts}")
else:
print("See you soon")
# In[ ]: