【发布时间】:2021-03-16 00:53:41
【问题描述】:
我的任务是将用户输入添加到列表中最近选择的号码。例如:
if choice == 1:
table = int(input("Please select your table number(0-19): "))
if tables[i] == "AVAILABLE":
name = input("What is your name?: ")
tables.append(name)
当我运行它时,输入被附加到最后一个表选项,而不是用户选择的选项。例如,表选择是 5,用户名是“Sam” - Sam 显示在表 20 而不是表 5。
我应该使用 tables.insert 吗?对此有点失落。谢谢。
这是迄今为止的全部代码:
while True:
print("")
print("Welcome to Torrey's Restaurant")
print("=====Select Option to Continue=====")
print("1- Reserve a Table")
print("2- Clear Reservation")
print("3- Status of Tables")
print("0- Exit")
choice = int(input("Choice? "))
count = 0
tables = []
for i in range(20):
tables.append("AVAILABLE")
if choice == 0:
print("Thank you for using this program")
break
if choice == 1:
table = int(input("Please select your table number(0-19): "))
if tables[i] == "AVAILABLE":
name = input("What is your name?: ")
tables.append(name)
if not tables[i] == "AVAILABLE":
print("The table you selected is unavailable")
tables{i} = 可以保留或已保留的表的列表。
【问题讨论】:
-
你在使用 Python 吗?
-
是的,我正在使用 python,抱歉。
-
tables[i] 是什么意思?