Last active
April 9, 2023 17:33
-
-
Save tmitzka/0b105d8071a014cc3d51dfafe0cf485a to your computer and use it in GitHub Desktop.
Cat age converter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Convert cat years to human years.""" | |
# Build conversion dictionary: keys are cat years, values are human years. | |
conversion = {1: 15} | |
for age in (2, 3): | |
conversion[age] = conversion[age - 1] + 6 | |
for age in range(4, 21): | |
conversion[age] = conversion[age - 1] + 4 | |
cat_age = int(input("Enter your cat's age in years: ")) | |
human_age = conversion.get(cat_age) | |
if human_age: | |
print(f"In human years, your cat would be {human_age} years old.") | |
else: | |
print("Please enter your cat's actual age (1 - 20).") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment