我正在为电影院制作座位计划,我在购买一个座位后添加座位请求时遇到问题。
以下是我一直在处理的代码
print("Options for Black Panther the movie")
def display_seats(taken_seats):
seating = []
for xd in range(15):
row = []
xda = 0
for xda in range(15):
row.append("#")
seating.append(row)
for x in taken_seats:
pos = x.split(",")
seating[(int(pos[0]) - 1)][(int(pos[1]))] = "X"
dx = 1
for row in seating:
if len(str(dx)) < 2:
de = " " + str(dx)
else:
de = dx
print ("Row: " + str(de) + " ".join(row))
dx = dx + 1
def list_options():
print ("1: View current seating")
print ("2: view price per row")
print ("3: View how much you are paying for now")
print ("4: Buying tickets")
print ("5: Exit these options")
new_input = input("Your choice: ")
return (new_input)
def purchase_seat(taken_seats):
print ("Would you like to view current seating availability? ")
print ("'1' = yes, '2' = no")
newinput = input("? ")
if newinput == "1":
display_seats(taken_seats)
x = True
while x == True:
cost = 0
print ("what row would you like to buy a seat on? ")
rowx = input("What row? ")
print ("What seat would you like to purchase?")
rowy = input("what seat? ")
if any((str(rowx) + "," + str(rowy)) for x in taken_seats):
print ("That seat is already taken, please choose another seat.")
elif int(rowx) > 15 or int(rowy) > 15:
print ("Invalid seating location, please choose another seat.")
else:
print ("seat purchased.")
cost = (2 * int(rowx))
x = False
return (cost, (str(rowx) + "," + str(rowy)))
taken_seats = []
sales = 0
quitter = 0
while quitter == 0:
new_input = list_options()
if new_input == "5":
quitter = 1
elif new_input == "4":
g = True
while g == True:
new_seat = purchase_seat(taken_seats)
taken_seats.append(new_seat[1])
print ("That will be: $ " + str(new_seat[0]))
sales = sales + new_seat[0]
print ("Would you like to purchase another seat?")
new_input = input("'1' = yes, '2' = no: ")
if new_input == "1":
pass
else:
g = False
elif new_input == "3":
print ("Total sales: $" + str(sales))
elif new_input == "2":
xd = 0
while xd < 15:
print ("Row for the theater " + str(xd + 1) + ": is $" + str((1 + (2 * xd)) + 1))
xd = xd + 1
elif new_input == "1":
display_seats(taken_seats)
else:
print ("invalid option.")
选择选项4并购买座位并继续回答输入您想要的行和当您输入另一个不同的行和座位坐标时的座位时,它会显示&#34;此座位已经被拍摄&#34;
我一直在寻找答案,我似乎无法找到答案。如果可以,请帮忙,谢谢。
答案 0 :(得分:1)
any
方法返回:
True
如果迭代的至少一个元素为真。
False
如果所有元素都为false或者iterable为空。
Refer Python Documentation for any method usage
第42行if any((str(rowx) + "," + str(rowy)) for x in taken_seats):
,实际应为if (str(rowx) + "," + str(rowy) in taken_seats):
。
这应检查列表taken_sets
中是否存在所选座位。