DEV Community

Discussion on: Daily Challenge #234 - Happy Birthday!

Collapse
 
vidit1999 profile image
Vidit Sarkar

This function checks if given age can be translated to the given required age,

# checks if age can be translated to 20 or 21
def isPossible(age : int, changedAge : int) -> bool:
    return age > 21 and age%2 == changedAge%2


print(isPossible(50, 20)) # output -> True
print(isPossible(50, 21)) # output -> False
print(isPossible(43, 20)) # output -> False
print(isPossible(66, 21)) # output -> False

This function returns the translated age and the base if possible,

# translates given age to 20 or 21 and prints the base
def translateAge(age : int):
    if(age > 21):
        return str(20 + age%2) + ", in base " + str(age//2)
    return "Not possible to translate"


print(translateAge(39)) # output -> 21, in base 19
print(translateAge(32)) # output -> 20, in base 16
print(translateAge(50)) # output -> 20, in base 25
print(translateAge(20)) # output -> Not possible to translate