将来自输入变量的数据存储在列表中

Storing data from input-variable in a list

我目前正在使用 Python 学习一门编程学科,并且即将参加考试。 170行的代码已上传,口试准备,但我想改进一些地方。

在第一部分中,我在列表中存储输入时遇到了困难,这些输入是使用我的程序来自“'respondent'”的身高、体重和出生年份。这些输入稍后将用于计算 BMI 并提供一些健康提示。

我曾尝试在许多网站上寻求帮助并使用这些建议。也许我的代码有问题?

# Input from respondent
Name = input('Type in your name : ')
Birthyear = input('Type in your birth year : ')
Height = input('Type in your height in inches: ')
Weight = input('Type in your weight in pounds : ')

Informations = (f'\n\nName\t\t: {Name.capitalize()}\n'
                 f'Birthyear\t: {Birthyear.capitalize()}\n'
                 f'Height\t\t: {Height.capitalize()}\n'
                 f'Weight\t\t: {Weight.capitalize()}\n')

print(Informations)

在此之后,我希望将输入存储在一个包含身高、体重和出生年份等虚构信息的列表中,如下所示:

# Create list with heights(BMItest_H), weights(BMItest_W) and birth year(BMItest_B) from 
fictional BMI test persons
BMItest_H = [70, 80, 78, 78, 75, 74, 77, 76]
BMItest_V = [176, 204, 199, 200, 187, 181, 180, 182]
BMItest_B = [1994, 1992, 1992, 1990, 1989, 1991, 1988, 1990]

您可以简单地循环并追加到列表中以获得多个“响应者”。

以 10 位受访者为例:

Birthyear_list = []
Height_list = []
Weight_list = []
name_list = []
respondents = 10
for n in range(respondents):
    # Input from respondent
    Name = input('Type in your name : ')
    Birthyear = input('Type in your birth year : ')
    Height = input('Type in your height in inches: ')
    Weight = input('Type in your weight in pounds : ')

    Informations = (f'\n\nName\t\t: {Name.capitalize()}\n'
                    f'Birthyear\t: {Birthyear.capitalize()}\n'
                    f'Height\t\t: {Height.capitalize()}\n'
                    f'Weight\t\t: {Weight.capitalize()}\n')
    Birthyear_list.append(Birthyear)
    Height_list.append(Height)
    Weight_list.append(Weight)
    name_list.append(Name)

    print(Informations)
print(Birthyear_list)
print(Height_list)
print(Weight_list)
print(name_list)