This repository has been archived by the owner on Mar 4, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
question.py
74 lines (60 loc) · 2.14 KB
/
question.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
67
68
69
70
71
72
73
74
def variable(question, variable_list):
while True:
answer = raw_input(question)
if answer in variable_list:
break
else:
print "Oops! You misspelled your variable name. Try again..."
return answer
def digit(question):
while True:
answer = raw_input(question)
answer_without_comma = answer.replace(',', '')
if str.isdigit(answer_without_comma):
break
else:
print "Oops! That was no valid number. Try again..."
return answer
def digit_and_date(question):
while True:
answer = raw_input(question)
answer_without_whitespace = answer.replace(' ', '')
answer_without_comma = answer_without_whitespace.replace(',', '')
if str.isdigit(answer_without_comma) and answer.count(',') == 2:
break
else:
print "That was no valid input. Follow the example and try again..."
return answer_without_whitespace
def digit_plate(question, number_of_plates):
while True:
answer = raw_input(question)
if str.isdigit(answer) and int(answer) in range(1, number_of_plates + 1):
break
else:
print "Oops! That was no valid number. Try again..."
return answer
def digit_station(question, stations):
while True:
answer = raw_input(question)
if str.isdigit(answer) and answer in stations:
break
else:
print "Oops! That was not a valid station_ID. Choose from the station(s) listed above."
return answer
def digit_with_constraint(question):
while True:
answer = raw_input(question)
answer_without_comma = answer.replace(',', '')
if str.isdigit(answer_without_comma) and int(answer_without_comma) <= 2:
break
else:
print "Oops! That was no valid number. Try again..."
return answer
def digit_with_plate_constraint(question):
while True:
answer = raw_input(question)
if str.isdigit(answer) and int(answer) <= 4:
break
else:
print "Oops! That was no valid number. Try again..."
return answer