-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinputs.py
163 lines (128 loc) · 4.6 KB
/
inputs.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
from utilities import timeFormat
def getPassengers(maximum):
while(True):
try:
passenger = input("? Enter the number of passengers (max. " + str(maximum)+ "): ")
if not passenger:
return 1
passenger = int(passenger)
if (passenger < 0 or passenger > maximum):
raise Exception(f"Invalid passengers number. You added {passenger} but the possible passengers are 1 or " + str(maximum))
return passenger
except Exception as err:
print(err)
def getPositiveInt(inputText, errorText):
while(True):
try:
inp = input(inputText)
if not inp:
return 0
inp = int(inp)
if (inp < 0):
raise Exception(errorText)
return inp
except Exception as err:
print(err)
def getExcessiveCarrage():
while(True):
try:
excessive_carrage = input("? Enter the weight of the luggage (press enter or 0 if none): ")
if not excessive_carrage:
return 0
excessive_carrage = int(excessive_carrage)
if (excessive_carrage < 0):
raise Exception(f"The weight cannot be negative.")
return excessive_carrage
except Exception as err:
print(err)
def getTowingWeight():
while(True):
try:
towingWeight = input("? Enter the weight (kg) of towing (press enter or 0 if none): ")
if not towingWeight:
return 0
towingWeight = int(towingWeight)
if (towingWeight < 0):
raise Exception(f"The weight cannot be negative.")
return towingWeight
except Exception as err:
print(err)
def getTime():
while(True):
try:
time = input("? Enter the departure time (format HH:MMPM/AM such as 12:00AM): ")
formTime = timeFormat(time)
return formTime
except Exception as err:
print(err)
def getInputWithComparisonList(text, array, default):
while(True):
try:
inp = input(text)
if not inp:
return default
if inp not in array:
raise Exception("The value you added is not inside the possible values of "+str(array))
return inp
except Exception as err:
print(err)
def getExperience():
while(True):
try:
years = input("? Enter the experience years: ")
if not years:
return 0
years = int(years)
if (years < 0):
raise Exception(f"The experience cannot be negative.")
return years
except Exception as err:
print(err)
def getServiced():
while(True):
try:
service = input("? Is the car serviced (yes or no): ")
if not service or (service).lower() == "no":
return False
if ((service).lower() == "yes"):
return True
else:
raise Exception(f"Invalid. Only yes or no")
except Exception as err:
print(err)
## FLIGHT INPUTS!
def getAverageLuggage(maximum):
while(True):
try:
inp = input(f"? Enter the average weight (kg) of the luggage (max. {maximum}kg): ")
if not inp:
return 0
inp = int(inp)
if (inp < 0 or inp > maximum):
raise Exception(f"The luggage weight can be between 0 and {str(maximum)}")
return inp
except Exception as err:
print(err)
def getRatio():
while(True):
try:
inp = input("? Enter the female ratio (between 0 and 1): ")
if not inp:
return 0
inp = float(inp)
if (inp < 0 or inp > 1):
raise Exception(f"Invalid ratio: value can be between 0 and 1")
return inp
except Exception as err:
print(err)
def getWindDirection():
while(True):
try:
inp = input("? Enter the wind direction (head or tail): ")
if not inp or inp == "tail":
return "tail_wind"
if inp == "head":
return "head_wind"
raise Exception("The wind direction can be head or tail")
except Exception as err:
print(err)