Create utils.py
Browse files- src/utils.py +26 -0
src/utils.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
def plural(value, singular, plural):
|
| 2 |
+
"""
|
| 3 |
+
Return the correct singular or plural word.
|
| 4 |
+
"""
|
| 5 |
+
return singular if value == 1 else plural
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def format_result(result):
|
| 9 |
+
"""
|
| 10 |
+
Convert the comparison result into a readable sentence.
|
| 11 |
+
"""
|
| 12 |
+
|
| 13 |
+
if result["same_age"]:
|
| 14 |
+
return (
|
| 15 |
+
f"Hello, {result['name']}!\n\n"
|
| 16 |
+
f"You and {result['other_name']} are exactly the same age. 🎉"
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
return (
|
| 20 |
+
f"Hello, {result['name']}!\n\n"
|
| 21 |
+
f"You're "
|
| 22 |
+
f"{result['years']} {plural(result['years'], 'year', 'years')}, "
|
| 23 |
+
f"{result['months']} {plural(result['months'], 'month', 'months')}, and "
|
| 24 |
+
f"{result['days']} {plural(result['days'], 'day', 'days')} "
|
| 25 |
+
f"{result['relation']} than {result['other_name']}. 🎉"
|
| 26 |
+
)
|