【发布时间】:2021-10-07 01:04:17
【问题描述】:
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")
我想知道在他们输入他们喜欢的汽车号码后如何获得输出“(他们的选择)是一辆好车”。
【问题讨论】:
-
int
1不是字符串"1. Hyundai"。考虑使用dict?而且每一行都有更多的错误...... -
使用
options[0]Wher Well工作时有超过10个选项。您应该使用更通用的设计。比如只使用输入值作为列表的索引。 -
如果用户输入
0,您将打印Exit is a nice car。
标签: python python-3.x python-2.7