I wrote this little script to calculate dog years. The first two dog years are 10.5 human years and all other years following are worth 4.
human_age = int(input("Enter the human age to convert it to doggy years: "))
valid = (human_age <=2)
def convert_to_dog_years(human_age):
if valid:
dog_years = human_age * 10.5
print('Dog age is:', int(dog_years))
elif not valid:
dog_years = ((((human_age - 2) * 4) + 21))
print('Dog age is:', int(dog_years))
convert_to_dog_years(human_age)
I was thinking something more along those lines: I would like to specify the mathematical operations giving them two names one for numbers from 0-2 and the other from 2 and up. Then I would like to use a boolean to decide which math process I want to apply.
Is this possible in python?
0-2 = dog_years = human_age * 10.5
>=2 = dog_years = ((((human_age - 2) * 4) + 21))
human_age = int(input("Enter the human age to convert it to doggy years: "))
valid = (human_age <=2)
def convert_to_dog_years(human_age):
if valid 0-2 else 2&up
print('Dog age is:', int(dog_years))
convert_to_dog_years(human_age)
human_ageas one line:human_age = int(input(....), why0-2is there a better variable choice? what's the issue with first choice, both cases do make use of boolean anyways with the help ofifstatement.