有人能给我解释一下独立程序和库程序的含义和区别吗?应该修改此代码,以便它可以作为独立的库模块(??)运行。你知道吗
我一直在尝试拆分和定义函数,但我不知道如何在这个函数中定义函数。因为这是一个简单的公式。你知道吗
代码是荷兰语的,但我确信它很清楚。体重指数
谢谢你的帮助
import sys
def main():
count = 0
closeprogram = False
weight = float(input("Hoeveel weegt u (in kg)?: "))
height = (float(input("Hoelang bent u (in cm)?: "))/100)
bmi = round(weight / (height * height))
while (not klaar and count < 5): #Men kan 5 kéér het BMI berekenen
print("\nDit programma berekent uw BMI.")
if weight < 0 or weight > 150:
print("ERROR, uw gewicht moet tussen de 0 en 150 kg liggen.")
continue
if height <= 0:
print("ERROR, uw lengte moet hoger dan 0 cm zijn.")
continue
else:
if bmi < 19:
print("\nUw BMI is",bmi,", dit houdt in dat u ONDER het gemiddelde zit. Vreten!!")
elif bmi >= 19 and bmi <= 25:
print("\nUw BMI is",bmi,", u bent HEALTHY!")
elif bmi > 25 and bmi <= 35:
print("\nUw BMI is",bmi,", dit houdt in dat u BOVEN het gemiddelde zit. Sporten!!")
else:
print("\nERROR, please try again")
break
count = count + 1
if count == 5:
closeprogram = True
main()
这意味着它可以作为模块导入或作为脚本执行,通常使用:
相关问题 更多 >
编程相关推荐