- 此问题在此处已有答案**:
How can I read inputs as numbers?(10个答案)
昨天关门了。
下面是代码:
print("Welcome to the weight maintenance calculator!")
startWeight = float(input("Input your start weight, in kilograms: "))
height = float(input("Enter your height in centimetres: "))
sex = input("Enter your sex (M/F): ")
age = float(input("Enter your age: "))
dailyActivity = input("Rank your activity level, from 0-5: ")
if ((sex == "M") or (sex == "m")):
startWeightBmr = int((10 * startWeight) + (6.25 * height) - (5 * age) + 5)
if (dailyActivity == 0):
caloriesUsedCurrently = startWeightBmr + 300
print(caloriesUsedCurrently)
if (dailyActivity == 1):
caloriesUsedCurrently = startWeightBmr + 350
print(caloriesUsedCurrently)
if (dailyActivity == 2):
caloriesUsedCurrently = startWeightBmr + 400
print(caloriesUsedCurrently)
无论如何,如果运行它,您将非常清楚地看到问题-无论您输入的数字是多少dailyActivity变量caloesUsedCurrently的值为0、1或2。我想知道if块是否有问题,以及它们是否正在执行。有人能指导我吗?它会运行,所以没有错误消息。这让一切都变得更加混乱,请帮帮我!
我试着在IDLE中运行它,看看是否是VSCode的问题,但是没有,因为我怀疑是我的代码。
1条答案
按热度按时间9nvpjoqh1#
尝试:
dailyActivity = int(input("Rank your activity level, from 0-5: "))
代码: