python - 输入数字时如何显示包含数字的列表
问题描述
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")
我想知道在他们输入他们喜欢的汽车号码后如何获得输出“(他们的选择)是一辆好车”。
解决方案
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")
推荐阅读
- javascript - 如何将返回的数据整理成更好的模型
- java - 连接 PersistenceManagerFactory 和 Persistence.xml 时出错
- node.js - Angular:TypeError:无法读取未定义的属性“地图”
- bash - 如何将文件中的一行放入表中(变量)
- reactjs - 在渲染方法中使用道具作为更改 UI 的条件?
- swift - 如何保证 inout 参数不会改变类型并且不会在函数中变为 nil
- model-view-controller - 301 重定向循环 - 如何限制重定向
- vim - 如何禁用 Slimv 对非 Lisp 文件的自动缩进?
- terraform - 如何做一个数据源的terraform模块?
- javascript - 如何修复在选项卡中不起作用的“加载更多”功能?