【发布时间】:2021-08-21 16:10:31
【问题描述】:
我是 Python 新手,仅供参考。我将输入作为患者姓名、患者 ID 号、身高和体重,我有用于计算他们的体重指数的功能代码。用户可以继续存储输入,直到他们“退出”或为患者 ID 输入负值。
问题:我还需要将这些输入存储在二维列表(列表列表)中,然后能够输出所有患者姓名的报告,后跟他们的 BMI 编号,加上状态我已经计算过的类别(肥胖、体重不足等)。以下是我目前所有可用的代码(虽然不漂亮):
# Give the user input options.
print("\nWelcome to patient entry. What would you like to do?")
# Set an initial value for choice other than the value for 'quit'.
choice = ''
# Start a loop that runs until the user enters the value for 'quit'.
while choice != 'q':
# Give all the choices in a series of print statements.
print("\n[1] Enter Patient Info.")
print("[q] Enter q to quit.")
# Ask for the user's choice.
choice = input("\nWhat would you like to do? ")
# Respond to the user's choice.
if choice == '1':
patient_name = (input("Enter patient name: "))
patient_id = int(input("Enter patient ID number: "))
while True:
height = int(input("Enter your height in inches: "))
try:
val = int(height)
if val < 0: # if not a positive, ask for input again
print("Sorry, input has to be a positive number, try again")
break
except ValueError:
print("That's not an number!")
while True:
weight = int(input("Enter your weight in pounds: "))
try:
val = int(weight)
if val < 0: # if not a positive int, ask for input again
print("Sorry, input has to be a positive number, try again")
continue
break
except ValueError:
print("That's not an number!")
# CDC formulat--https://www.cdc.gov/nccdphp/dnpao/growthcharts/training/bmiage/page5_2.html
BMI = ((float(weight) / float(height) ** 2) * 703)
# print(f"Your BMI is {BMI}")
print("Your BMI is: {0} and you are: ".format(round(BMI, 2)), end='')
# conditions
if (BMI < 16):
print("severely underweight")
elif (BMI >= 16 and BMI < 18.5):
print("underweight")
elif (BMI >= 18.5 and BMI < 25):
print("Healthy")
elif (BMI >= 25 and BMI < 30):
print("overweight")
elif (BMI >= 30):
print("severely overweight")
elif choice == 'q':
print("\nThanks for playing. See you later.\n")
exit()
else:
print("\nI don't understand that choice, please try again.\n")
patient_name = (input("Enter patient name: "))
patient_id = int(input("Enter patient ID number: "))
while True:
height = int(input("Enter your height in inches: "))
try:
val = int(height)
if val < 0: # if not a positive, ask for input again
print("Sorry, input has to be a positive number, try again")
continue
break
except ValueError:
print("That's not an number!")
while True:
weight = int(input("Enter your weight in pounds: "))
try:
val = int(weight)
if val < 0: # if not a positive int, ask for input again
print("Sorry, input has to be a positive number, try again")
continue
break
except ValueError:
print("That's not an number!")
【问题讨论】:
标签: python python-3.x