-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
32 lines (30 loc) · 906 Bytes
/
utils.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
def inputNumber(message):
"""
Asks the user for a enter a number based on the message being asked
:param message: What message is asked to the user
:return: number user entered
"""
while True:
try:
userInput = int(input(message))
except ValueError:
print("Oops. Not a valid input. Must be number.")
continue
else:
return userInput
def inputNumberOrReturn(message):
"""
Asks the user for a enter a number based on the message being asked
:param message: What message is asked to the user
:return: number user entered
"""
guess = input(message)
if not guess:
return 0
try:
# CONVERT GUESS INTO A NUMBER
guess = int(guess)
except ValueError:
print("Oops. We need a number or return which defaults to 0")
else:
return guess