Click here to see step 3 到目前为止,我认为第1步和第2步步入正轨,但是如果我可以改进它,请告诉我。对于第3步,我不知道如何显示所有20行(如果已保留或未保留)以及输入用户的名称。
reserveDict = {}
def reserve():
global reserveDict
tablenum = int(input("Enter a number: "))
if tablenum not in reserveDict.keys():
name = input("Table is avaiable, please enter your name: ")
reserveDict[tablenum] = name
else:
print("Table is unavaiable")
def remove():
global tablenum
tablenum = int(input("Enter the table number: "))
del reserveDict[tablenum]
def report():
global reserveDict
count = len(reserveDict)
while(True):
print("1- Reserve a Table")
print("2- Clear Reservation")
print("3- Report")
print("0- Exit")
choice = int(input("Choose a option "))
if choice == 1:
reserve()
elif choice == 2:
remove()
答案 0 :(得分:-1)
我没有改进您的步骤1、2。我只是构建了步骤3和4。这是完整的代码。
reserveDict = {}
def reserve():
global reserveDict
tablenum = int(input("Enter a number: "))
if tablenum not in reserveDict.keys():
name = input("Table is avaiable, please enter your name: ")
reserveDict[tablenum] = name
else:
print("Table is unavaiable")
def remove():
global tablenum
tablenum = int(input("Enter the table number: "))
del reserveDict[tablenum]
def report():
global reserveDict
for i in range(20):
if i in reserveDict.keys():
print(i,reserveDict[i])
else:
print(i,"available")
while(True):
print("1- Reserve a Table")
print("2- Clear Reservation")
print("3- Report")
print("0- Exit")
choice = int(input("Choose a option "))
if choice == 1:
reserve()
elif choice == 2:
remove()
elif choice == 3:
report()
elif choice == 0:
exit()