我用Python构建了一个用于预订剧院座位的代码。代码运行良好,除了我需要能够重复代码在一个循环,所以一旦一些座位被预订,你可以选择预订更多的座位。在
代码如下:NumSeat = input ("Please enter the number of seats you desire: ")
print (" ")
import re
if re.match("[0-9]", NumSeat):
if int(NumSeat) > 6:
print ("You may only book a maximum of 6 seats")
else:
if int(NumSeat) < 1:
print ("You must book at least 1 seat")
else:
SeatRow = input ("Please enter the row you want to sit in: ")
if len(SeatRow) > 1:
print ("Invalid row")
else:
if SeatRow.count ("A") or SeatRow.count ("a") == 1:
print ("The seats avaiable in row", SeatRow, "for", int(NumSeat), "people are", RowA[0],"-", RowA[int(NumSeat)-1])
RowA = RowA[int(NumSeat):]