我正在尝试创建一个BMI计算器,我有一个人员列表,我的目标是遍历每个人,询问他们的身高体重,并将其存储在一个变量中。每次问他们,我都试图让他们说出自己的名字
recipients = ["John", "Dee", "Aleister", "Lilith", "Paul", "Reggy"]
for recipient in recipients:
height = int(input("What is your height " + str(recipients)))
输出:
What is your height ['John', 'Dee', 'Aleister', 'Lilith', 'Paul', 'Reggy']
您甚至可以使用列表理解:
您可以使用for循环来实现这一点
或者将
len()
与列表索引一起使用您可以执行for循环,例如:
相关问题 更多 >
编程相关推荐