-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfly.py
66 lines (50 loc) · 1.56 KB
/
fly.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
"""
Since Zortan has less gravity, residents can fly if they weight
less than or equal to 15 kgs in Zortan weight.
Louis wants to see which of his friends can fly.
Info:
-----
Our functions do only one thing at a time, this is called as `Single
Responsibility Principle` and important aspect of programming.
"""
from typing import Final
MAX_FLYING_WEIGHT: Final[float] = 15
def calc_weight(weight: float) -> float:
"""
Calculates Zortan Weight
------------------------
Look how the function just transforms data, from float to float.
"""
return (weight + 32) / 8
def can_fly(weight: float) -> bool:
"""
Returns if you can fly
----------------------
This function is a nice example for data transformation, we convert
float values to boolean values!! Nice isn't it!
"""
return weight <= MAX_FLYING_WEIGHT
def flying_friends(friends: dict[str, float]) -> None:
"""
Displays flying and non-flying friends
Note:
-----
No data transformation here.
We are printing the output to console, the function doesn't return anything.
"""
for name, earth_weight in friends.items():
zortan_weight = calc_weight(earth_weight)
if can_fly(zortan_weight):
print(f"{name}: {zortan_weight} kgs can fly on Zortan!")
else:
print(f"{name}: {zortan_weight} kgs can only walk on Zortan.")
def main():
friends: dict[str, float] = {
"Cece": 54,
"Roko": 88,
"Chiko": 50,
"Niko": 102,
"Ziko": 90,
}
flying_friends(friends)
main()