首页 > 解决方案 > 输入数字时如何显示包含数字的列表

问题描述

options = ["1. Hyundai", "2. Benz", "3. BMW", "4. Honda", "5. Toyota", "6. GMC", "7. Cadillac", "0.Exit"]

for i in options:
    print(i)
answer = int(input("choose a number from the list above "))
for index in range(len(options)):
    if answer == options[0]:
        print(f"{options} is a nice car")


if  answer == 0:
    print("Goodbye")

我想知道在他们输入他们喜欢的汽车号码后如何获得输出“(他们的选择)是一辆好车”。

标签: pythonpython-3.xpython-2.7

解决方案


options = ["1. Hyundai", "2. Benz", "3. BMW", "4. Honda", "5. Toyota", "6. GMC", "7. Cadillac", "0.Exit"]

for i in options:
    print(i)
answer = int(input("choose a number from the list above "))
if  answer == 0:
    print("Goodbye")
else:
    print(f"{options[answer-1]} is a nice car")

推荐阅读