Friday, February 18, 2022

Cat years, Dog years Python Codewars

Task:

I have a cat and a dog.

I got them at the same time as kitten/puppy. That was humanYears years ago.

Return their respective ages now as [humanYears,catYears,dogYears]

NOTES:

  • humanYears >= 1
  • humanYears are whole numbers only

Cat Years

  • 15 cat years for first year
  • +9 cat years for second year
  • +4 cat years for each year after that

Dog Years

  • 15 dog years for first year
  • +9 dog years for second year
  • +5 dog years for each year after that

Solution:


def human_years_cat_years_dog_years(human_years):
    result = []
    i = human_years
    if i == 1:
        result.append(i)
        result.append(15)
        result.append(15)
    if i == 2:
        result.append(i)
        result.append(15+9)
        result.append(15+9)
    if i >=3:
        result.append(i)
        result.append(15+9+(i-2)*4)
        result.append(15+9+(i-2)*5)       


    return result

print(human_years_cat_years_dog_years(10))

def human_years_cat_years_dog_years(x):
    return [x, 24+(x-2)*4 if (x != 1) else 15, 24+(x-2)*5 if (x != 1) else 15]

Training on Cat years, Dog years | Codewars



Related Posts


No comments :

Post a Comment