-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path04_functions.py
More file actions
41 lines (28 loc) · 1.16 KB
/
Copy path04_functions.py
File metadata and controls
41 lines (28 loc) · 1.16 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
31
32
33
34
35
36
37
38
39
40
41
"""
Simple examples of Python functions with parameters and return values.
"""
from typing import List
def add(a: float, b: float) -> float:
"""Return the sum of two numbers."""
return a + b
def repeat_phrase(phrase: str, times: int = 1) -> List[str]:
"""Return the phrase repeated `times` times as a list of strings."""
return [phrase for _ in range(times)]
def summarize_day(workouts_done: int, hours_coded: float) -> str:
"""Summarize the day based on training and coding activity."""
if workouts_done > 0 and hours_coded >= 2:
return "Great job, you trained and coded today."
if workouts_done > 0:
return "Nice training session. Consider adding some coding time."
if hours_coded >= 2:
return "Strong coding session. Get a workout in next time."
return "Light day. Small steps still count, keep going."
def main() -> None:
print("Adding numbers:", add(5, 7))
print("\nRepeating phrase:")
for line in repeat_phrase("Focus mode activated", times=3):
print("-", line)
print("\nDaily summary:")
print(summarize_day(workouts_done=1, hours_coded=2.5))
if __name__ == "__main__":
main()