我不明白为什么我会看到“进程已完成,退出代码为0”,而不是提示“请输入狗龄”

问题描述 投票:0回答:1

我是pycharm新手,请帮助我

我正在尝试编写一个程序,可以将狗的年龄转换为人类的年龄,并且当我尝试测试它时。它没有给我任何提示。我不知道下一步该做什么以及我的代码哪里出了问题:

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")
python pycharm
1个回答
0
投票

您需要执行计算器功能:

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()
© www.soinside.com 2019 - 2024. All rights reserved.