Skip to content

Instantly share code, notes, and snippets.

@tmitzka
Last active April 9, 2023 17:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tmitzka/0b105d8071a014cc3d51dfafe0cf485a to your computer and use it in GitHub Desktop.
Save tmitzka/0b105d8071a014cc3d51dfafe0cf485a to your computer and use it in GitHub Desktop.
Cat age converter
"""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