我正在写一个程序,它将提示用户输入6个想要计算其体重指数的个人的名字,然后提示每个人的身高和体重。然而,我似乎不知道如何从我创建的列表中选择一个人。它会一直选择所有输入的名字。有人能建议我如何一次只选择一个人吗?谢谢
print ("This program will help calculate the body mass index of 6 people")
users = str(input("Please enter the names of the 6 users who want to calculate thier BMI: "))
individuals = list()
individuals.append(users)
userA = individuals[0:1]
for userA in individuals:
height = int(input("In inches, how tall are you? "))
weight = int(input("In pounds, how much do you weight? "))
BMI = print(userA, "Your BMI is: ", weight * 703/height**2)发布于 2020-10-10 01:47:39
在输入上循环六次,所有的列表都将工作,例如:
print ("This program will help calculate the body mass index of 6 people")
individuals = list()
for i in range(6):
user = str(input("Please enter the names of the 6 users who want to calculate their BMI: "))
individuals.append(user)
for user in individuals:
print("Calculating for", user)
height = int(input(user + ", in inches, how tall are you? "))
weight = int(input(user + ", in pounds, how much do you weight? "))
BMI = print(user + ", your BMI is: ", weight * 703/height**2)编辑
以下是在列表中存储BMI的版本
print ("This program will help calculate the body mass index of 6 people")
individuals = list()
for i in range(6):
user = str(input("Please enter the names of the 6 users who want to calculate their BMI: "))
individuals.append(user)
BMIs = []
for user in individuals:
print("Calculating for", user)
height = int(input(user + ", in inches, how tall are you? "))
weight = int(input(user + ", in pounds, how much do you weight? "))
BMIs.append(user + ", your BMI is: " + str(weight * 703/height**2))
for BMI in BMIs:
print(BMI)发布于 2020-10-10 01:44:26
试试这个吧
print ("This program will help calculate the body mass index of 6 people")
users = str(input("Please enter the names of the 6 users who want to calculate thier BMI (comma separated): "))
users = users.split(',')
print(users)
userA = users[0]
userA
#This program will help calculate the body mass index of 6 people
#Please enter the names of the 6 users who want to calculate thier BMI (comma separated): a,b,c,d
#['a', 'b', 'c', 'd']
#'a'发布于 2020-10-10 01:44:03
这样行得通吗?
Testrun:
python BMI.py
Enter height in meters: 1.75
Enter weight in kg: 64
Your BMI is: 20.897959183673468 and you are: HealthyPython代码:
# getting input from the user and assigning it to user
height = float(input("Enter height in meters: "))
weight = float(input("Enter weight in kg: "))
# the formula for calculating bmi
bmi = weight/(height**2)
# ** is the power of operator i.e height*height in this case
print("Your BMI is: {0} and you are: ".format(bmi), 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")来自:https://www.includehelp.com/python/bmi-body-mass-index-calculator.aspx
这回答了你的问题吗?
致以敬意,
将要。
https://stackoverflow.com/questions/64284821
复制相似问题