forked from powerexploit/Awesome-Python-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathguessinggame.py
More file actions
28 lines (23 loc) · 829 Bytes
/
Copy pathguessinggame.py
File metadata and controls
28 lines (23 loc) · 829 Bytes
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
import random
def start(limit, chances):
number = random.randint(1, limit)
win = False
while chances > 0:
guess = int(input())
if guess == number:
print("HOORAY YOU WON!!!")
win = True
break
elif guess < number:
print("Your guess was too low: Guess a number higher than", guess)
else:
print("Your guess was too high: Guess a number lower than", guess)
chances -= 1
if win is not True:
print("YOU LOSE!!! The number is", number)
if __name__ == "__main__":
print("Number guessing game")
limit = int(input("Enter range of number: "))
chances = int(input("Enter the number of chances: "))
print("Guess a number (between 1 and your range): ")
start(limit, chances)