-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNumberGuesser.py
More file actions
69 lines (69 loc) · 1.99 KB
/
NumberGuesser.py
File metadata and controls
69 lines (69 loc) · 1.99 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
63
64
65
66
67
68
69
import random
attempts = 5
rangex = 100
def menu():
choice = input("Enter play, credits, quit, gamble, or advanced: ")
if choice.lower() == "play":
play()
elif choice.lower() == "credits":
creditsx()
elif choice.lower() == "quit":
quitx()
elif choice.lower() == "gamble":
gamble()
elif choice.lower() == "advanced":
advanced()
else:
print("enter a valid option")
menu()
def play():
global rangex
global attempts
attempt = 0
number = random.randint(1, rangex)
print("Try to guess what number im thinking of. \nGo ahead, the number is between 1 -", rangex)
print("You have", attempts,"attempts.")
while attempt < attempts:
guess = input("")
if not guess.isdigit():
print("Please enter a number")
continue
guess = int(guess)
if guess == number:
print("Yay! good job you guessed it")
break
elif guess < number:
print("Oh no! you are too low, try again")
attempt += 1
elif guess > number:
print("Oh no! you are too high, try again")
attempt += 1
if attempt >= attempts:
print("Oh no! you ran out of attempts...")
def advanced():
global rangex
global attempts
while True:
rangex = input("Enter the desired range of the number to guess:\n")
if not rangex.isdigit():
print("Enter a digit.")
continue
else:
rangex = int(rangex)
break
while True:
attempts = input("Enter the number of attempts allowed: \n")
if not attempts.isdigit():
print("Enter a digit.")
continue
else:
attempts = int(attempts)
break
print("Settings changed! The range is now", rangex, "and the number of attempts is", attempts)
menu()
def creditsx():
print("BY JOSH BOTHELL AND MATTHEW WALKER")
menu()
def quitx():
exit()
menu()