-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwater5.py
More file actions
30 lines (24 loc) · 1.03 KB
/
water5.py
File metadata and controls
30 lines (24 loc) · 1.03 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
def water_left(astronauts, water_left, days_left):
for argument in [astronauts, water_left, days_left]:
try:
# If argument is an int, the following operation will work
argument / 10
except TypeError:
# TypError will be raised only if it isn't the right type
# Raise the same exception but with a better error message
raise TypeError(f"All arguments must be of type int, but received: '{argument}'")
daily_usage = astronauts * 11
total_usage = daily_usage * days_left
total_water_left = water_left - total_usage
if total_water_left < 0:
raise RuntimeError(f"There is not enough water for {astronauts} astronauts after {days_left} days!")
return f"Total water left after {days_left} days is: {total_water_left} liters"
def alert_navigation_system(err):
print (err)
def main():
try:
print(water_left("3", "200", None))
except RuntimeError as err:
alert_navigation_system(err)
if __name__ == '__main__':
main()