I am trying to write a program that can convert dog age to human age and when I try to test it. It does not give me any prompt. I have no idea what to do next and where is wrong with my code:
def calculator():
dog_age = input("Please enter dog age ")
try:
dog_age = float(input("what is your dog age?: "))
if dog_age < 0:
print("age can not be a negative number")
elif dog_age <= 1:
print(dog_age * 15)
elif dog_age <= 2:
print(dog_age * 12)
elif dog_age <= 3:
print(dog_age * 9.3)
elif dog_age <= 4:
print(dog_age * 8)
elif dog_age <= 5:
print(dog_age * 7.2)
elif dog_age >= 5:
print(dog_age * 7)
print("The given dog age", dog_age, "is", round(dog_age, 2),"in human years")
except ValueError:
print("please enter a valid number")
New contributor
Don is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
7
You need to execute your calculator function:
def calculator():
dog_age = input("Please enter dog age ")
try:
dog_age = float(input("what is your dog age?: "))
if dog_age < 0:
print("age can not be a negative number")
elif dog_age <= 1:
print(dog_age * 15)
elif dog_age <= 2:
print(dog_age * 12)
elif dog_age <= 3:
print(dog_age * 9.3)
elif dog_age <= 4:
print(dog_age * 8)
elif dog_age <= 5:
print(dog_age * 7.2)
elif dog_age >= 5:
print(dog_age * 7)
print("The given dog age", dog_age, "is", round(dog_age, 2),"in human years")
except ValueError:
print("please enter a valid number")
if __name__ == "__main__": # NEW
calculator()
1