【发布时间】:2022-01-03 18:59:54
【问题描述】:
我目前正在学习一门使用 Python 进行编程的科目,并且即将参加考试。 已上传 170 行代码,用于口试,但我想改进一些部分。
在第一部分中,我在使用我的程序将“受访者”的身高、体重和出生年份存储在列表中时遇到了困难。这些输入稍后将用于计算 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]
【问题讨论】:
标签: python python-3.x python-2.7