gpt4 book ai didi

python - Python 中的 BMI 计算器

转载 作者:太空宇宙 更新时间:2023-11-03 13:46:03 25 4
gpt4 key购买 nike

程序根据用户输入的体重和高度计算一个人的 BMI。但是,在我输入“公制”或“英制”并按回车键后,程序关闭。前三个打印功能工作正常,之后的任何内容都不会在我按下回车按钮后出现。我该如何解决这个问题?

print('\t\t\t BMI Calculator')
print('\t\t\t By Abdinasir Hussein')
print('\n Hello, this is a BMI Calculator!')

input('Do you wish to enter metric units or imperial units: ')

while input == 'metric':
height = float(input('Please enter your height input meters(decimals): '))
weight = int(input('Please enter your weight input kg: '))
bmi = weight/(height*height)

if bmi <= 18.5:
print('Your BMI is', bmi,'which means you are underweight.')

elif bmi > 18.5 and bmi < 25:
print('Your BMI is', bmi,'which means you are normal.')

elif bmi > 25 and bmi < 30:
print('your BMI is', bmi,'overweight.')

elif bmi > 30:
print('Your BMI is', bmi,'which means you are obese.')

else:
print('There is an error with your input')
print('Please check you have entered whole numbers\n'
'and decimals were asked.')

while input == 'imperial':
height = int(input('Please enter your height input inputches(whole number): '))
weight = int(input('Please enter your weight input pounds(whole number): '))
bmi = (weight*703)/(height*height)

if bmi <= 18.5:
print('Your BMI is', bmi,'which means you are underweight.')

elif bmi > 18.5 and bmi < 25:
print('Your BMI is', bmi,'which means you are normal.')

elif bmi > 25 and bmi < 30:
print('Your BMI is', bmi,'which means you are overweight')

elif bmi > 30:
print('Your BMI is', bmi,'which means you are obese.')

else:
print('There is an error with your input')
print('Please check you have entered whole numbers\n'
'and decimals were asked.')

input('\n\nPlease press enter to exit.')

我现在已经更改了它,但是我该如何编辑这个 block :

input = input('Do you wish to enter metric units or imperial units: ')

if input == 'metric':
height = float(input('Please enter your height input meters(decimals): '))
weight = int(input('Please enter your weight input kg: '))
bmi = weight/(height*height)

if bmi <= 18.5:
print('Your BMI is', bmi,'which means you are underweight.')

elif bmi > 18.5 and bmi < 25:
print('Your BMI is', bmi,'which means you are normal.')

elif bmi > 25 and bmi < 30:
print('your BMI is', bmi,'overweight.')

elif bmi > 30:
print('Your BMI is', bmi,'which means you are obese.')

else:
print('There is an error with you inputput')
print('Please check you have entered whole numbers\n'
'and decimals where asked.')

最佳答案

代替 while input == 'imperial':

使用

else: 
height = float(input('Please enter your height input inputches: '))
weight = int(input('Please enter your weight input pounds: '))

或者使用

elif input == 'imperial':
height = float(input('Please enter your height input inputches: '))
weight = int(input('Please enter your weight input pounds: '))
else:
print("Please enter any one of the units")`

关于python - Python 中的 BMI 计算器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20405610/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com