bmi计算器如何重新启动计算器,回到yesno在顶部

问题描述 投票:0回答:1
Take_Bmi=(input("Take bmi yes or no "))

if Take_Bmi == "yes":
    name1=input(" enter your name")
    height_m1=input(" enter your height in m")
    weight_kg1=input(" enter your weight")
    def bmi_calculator(name1,height_m1,weight_kg1):
        bmi = float(weight_kg1) / (float(height_m1)** 2)

#输入函数返回一个字符串。所以要得到你的输出,你需要用 "float() "来表示身高和体重:print("bmi:")

        if bmi < 25 :

            print(bmi)
            return name1 + " not overweight"
        else:
            print(bmi)

            return name1 + " is overweight"

   result= bmi_calculator(name1,float(height_m1),float(weight_kg1))
   print(result)

else:
    print("thank you")

我怎么喜欢重复这个测试,如打印(你想再次参加)。

回到你要不要去北京航空航天大学 是的 不是的,在上面

python function input
1个回答
0
投票

input 函数返回一个字符串.所以为了得到你的输出,你需要使用 "float() "来表示高度和重量。

bmi = float(weight_kg1) / (float(height_m1)** 2)

同时,你还需要 召唤 你的函数,例如

bmi_calculator(name1,float(height_m1),float(weight_kg1))
© www.soinside.com 2019 - 2024. All rights reserved.