-
Notifications
You must be signed in to change notification settings - Fork 0
/
ques_funcs.py
66 lines (59 loc) · 1.78 KB
/
ques_funcs.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
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
# Stores question functions
def ask_ok(prompt, retries=4, reminder='Please try again!'):
"""
This function defines a generic yes or no question.
"""
while True:
ok = input(prompt + ' [yes/no]\n')
if ok in ('y', 'ye', 'yes'):
return True
if ok in ('n', 'no', 'nop', 'nope'):
return False
retries = retries - 1
if retries < 0:
raise ValueError('invalid user response')
print(reminder)
def ask_to_continue(prompt, retries=4, reminder='Please try again!'):
"""
This function defines a generic continue confirmation.
"""
while True:
ok = input(prompt + ' [enter]\n')
if ok in ('\r'):
return True
retries = retries - 1
if retries < 0:
raise ValueError('invalid user response')
print(reminder)
def multi_choice_question(prompt, retries=4, reminder='Please try again!'):
"""
This function defines a generic yes or no question.
"""
while True:
ans = input(prompt + ' [1/0]\n')
if ans in ('1', 'one'):
return True
if ans in ('0', 'zero'):
return False
retries = retries - 1
if retries < 0:
raise ValueError('invalid user response')
print(reminder)
def ask_for_float_question(prompt, retries=4, reminder='Please try again!'):
"""
This function defines a generic yes or no question.
"""
while True:
ans = input(prompt + '\n')
if isfloat(ans):
return float(ans)
retries = retries - 1
if retries < 0:
raise ValueError('invalid user response')
print(reminder)
def isfloat(num):
try:
float(num)
return True
except ValueError:
return False