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
15cat years for first year+9cat years for second year+4cat years for each year after that
Dog Years
15dog years for first year+9dog years for second year+5dog 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
No comments :
Post a Comment