DNPotapov / Codewars-katas-

0 stars 0 forks source link

Twice as old (8 kyu) #14

Open DNPotapov opened 1 year ago

DNPotapov commented 1 year ago
def twice_as_old(dad_years_old, son_years_old):
    if son_years_old == 0:
        return dad_years_old
    count = 0
    save_dad = dad_years_old
    while(dad_years_old/son_years_old != 2 and dad_years_old != 0):
        dad_years_old -= 1
        count += 1
    if dad_years_old != 0:
        return count
    else:
        count = 0
        while(save_dad/son_years_old != 2):
            save_dad += 1
            count += 1
        return count
DNPotapov commented 1 year ago

Your function takes two arguments:

current father's age (years) current age of his son (years) Сalculate how many years ago the father was twice as old as his son (or in how many years he will be twice as old). The answer is always greater or equal to 0, no matter if it was in the past or it is in the future.

DNPotapov commented 1 year ago

https://www.codewars.com/kata/5b853229cfde412a470000d0