i writing code prints out seating arrangement , checks list of lists see if seat available (in list indicated '-' if empty) if empty replace '-' '#'. when check list of lists , replace indices @ lets [1][1] changes indices in [0][1], [2][1], [3][1]...etc. '#'
my code far:
globalseats = [] def create(rows, seats): global globalseats count = 0 row = [] seat = [] while count != rows: row.append('-') count += 1 counter = 0 while counter != seats: seat.append('-') counter += 1 globalseats.append(row) globalseats.append(seat) return globalseats def theater_list(): x in globalseats[0]: print(''.join(globalseats[1]) globalseats.append(globalseats[1]) print('\n') def print_theater(): del globalseats[0] del globalseats[1] elem in globalseats: print(''.join(map(str,elem))) print('\n') def sell_seat(row_number,seat_number): if globalseats[row_number][seat_number] == '#': return true else: globalseats[row_number][seat_number] = '#' return false
my code calls functions:
import theater rows = 10 seats_per_row = 20 local_theater = theater.create(rows,seats_per_row) theater.theater_list() theater.print_theater() if not theater.sell_seat(3,5): theater.print_theater() else: print('seat has been sold') theater.print_theater() # part makes sure same seat can not sold twice if not theater.sell_seat(3,5): theater.print_theater() else: print('seat has been sold') theater.print_theater()
Comments
Post a Comment