python 3 on jupyter notebook my code: def calculator(): # variable for human age human_age = 0.0
Question:
python 3 on jupyter notebook
my code:
def calculator(): # variable for human age human_age = 0.0 # to get the dog age by the user dog_age = input("Enter your dog's age ") try: # converting dog age variable to floatvariable dog_age = float(dog_age) # negative (including zero) age valuewill throw the error assert dog_age > 0 # condition to calculate dog age if dog_age <= 1 and dog_age > 0: # if dog age is between 0 and 1 human_age = 15 *dog_age elif dog_age > 1 and dog_age <=2: # if dog_age is between 1 and 2 human_age = 12 *dog_age elif dog_age > 2 and dog_age <=3: # if dog_age is between 2 and 3 human_age = 9.3 *dog_age elif dog_age > 3 and dog_age <=4: # if dog_age is between 3 and 4 human_age = 8 *dog_age elif dog_age > 4 and dog_age <=5: # if dog age is between 4 and 5 human_age = 7.2 *dog_age else: # if dog age is greaterthan 5 human_age = 7 *dog_age print(f"the given dog age {dog_age:.2f}in human _age is {human_age:.2f}") # exceptions except ValueError: # catch exception if inputis not a number print("Input must be numeric") except AssertionError: print("Input must be positive")
calculator()
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill