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

"How Old is Your Dog in Human Years?" Calculator In this assignment,you will write a program that calculates a dog's age in humanyears. The program will prompt the user for an age in dogyears and calculate that age in human years. Allow for int or

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()

"How Old is Your Dog in Human Years?" Calculator In this assignment, you will write a program that calculates a dog's age in human years. The program will prompt the user for an age in dog years and calculate that age in human years. Allow for int or float values, but check the user's input to make sure it's valid -- it should be numeric and positive. Otherwise, let the user know their input is not valid. You can use the following rules to approximately convert a medium-sized dog's age to human years: For the first year, one dog year is equal to 15 human years For the first 2 years, each dog year is equal to 12 human years For the first 3 years, each dog year is equal to 9.3 human years For the first 4 years, each dog year is equal to 8 human years For the first 5 years, each dog year is equal to 7.2 human years After that, each dog year is equal to 7 human years. (Note: This means the first 5 dog years are equal to 36 human years (5 * 7.2) and the remaining dog years are equal to 7 human years each.) Print the result in the following format, substituting for dog_age and human_age: "The given dog age dog_age is human_age in human years." Round the result to 2 decimal places. Note: If there is a 0 in the hundredths place, you can drop it, e.g. 24.00 can be displayed as 24.0.

Step by Step Solution

3.58 Rating (158 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

import math def dogtohumandogage Check if ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Electrical Engineering Questions!