python初学火车座位判断_python中的座位平面图

def display(taken_seats):

seating = []

xd = 0

while xd < 15: #creates the cinema seating map

row = []

xda = 0

while xda < 15:

row.append("#")

xda = xda + 1

xd = xd + 1

seating.append(row)

for x in taken_seats: #changes the seats that are taken to a "X"

pos = x.split(",")

seating[(int(pos[0]) - 1)][(int(pos[1]))] = "X"

dx = 1

for row in seating: #prints the rows.

if len(str(dx)) < 2:

de = " " + str(dx)

else:

de = dx

print "Row: " + str(de) + " ".join(row)

dx = dx + 1

taken_seats = ("1,12", "2,8", "5,5", "12,12")

display(taken_seats)

所有购买的座位都被放在“座位”的列表中,格式为“座位”

希望这有帮助!(我很抱歉它不是最干净的,它主要是迭代器。)

编辑:

要增加额外的座位,只需

^{pr2}$

将号码更改到所需的座位位置。在

要显示更新的座位,只需运行命令display(taken_seats)

带有菜单界面的代码: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 ("5: exit")

print ("4: buy ticket")

print ("3: view sales")

print ("2: view price per row")

print ("1: view current seating")

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 = (200 - (10 * 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 " + str(xd + 1) + ": is $" + str((200 - (10 * xd)) - 10))

xd = xd + 1

elif new_input == "1":

display_seats(taken_seats)

else:

print ("invalid option.")

在gaelephor.com中可以找到一个zip文件,其中包含要从文件中保存和加载的座位和销售的文件和代码

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值