#input
name = input("Enter your name:")
height = input ("Height:")
weight = input ("Weight:")
print("Weight:" + weight +"kg")
print("height:" + height +"m")
print("My name is " + name +"!")
#operations with decimal numbers
metres = float(height)
height_sqr = pow(metres,2)
kg = float(weight)
BMI = float(kg)/height_sqr
#print BMI results
print("BMI:" +str(BMI) +"Kg/M2")
如果您想要一个更优化的方法,这里是:
在这里,您既不必将输入作为字符串,然后将其转换为浮点,也不必使用函数来计算幂。 它还显示了你的体重指数的范围
代码的效率是一样的
相关问题 更多 >
编程相关推荐