-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGuessNumber.py
More file actions
50 lines (32 loc) · 1.3 KB
/
GuessNumber.py
File metadata and controls
50 lines (32 loc) · 1.3 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
from random import randint
name = input("What's your name: ").upper()
print(f"\nHello {name}, Welcome to Guess The Number!")
player_input = input("\nType a max number (i.e 10 for 1-10. 50 for 1-50. 100 for 1-100): ")
if player_input.isdigit():
player_input = int(player_input)
if player_input <= 0:
print(f"Type a number larger than 0 {name}")
else:
print(f"Type a number {name}!!")
random_number = randint(0, player_input)
guess_count = 5
while True:
player_guess = input("Enter your guess: ")
if player_guess.isdigit():
player_guess = int(player_guess)
if player_guess == random_number:
print(f"\nWell done {name}. That's correct!")
break
elif (player_guess > random_number) and (guess_count != 1):
print(f"Your guess is too high {name}. Try again \n")
guess_count -= 1
print(f"You have {guess_count} guesses left!\n")
elif (player_guess < random_number) and (guess_count != 1):
print(f"Your guess is too low {name}. Try again!\n")
guess_count -= 1
print(f"You have {guess_count} guesses left!\n")
else:
print("Oops! You're out of guesses. You lose!")
break
else:
print(f"Type a number {name}!!\n")