In: Computer Science
C1 | C2 | C3 | C4 | C5 | C6 | C7 | C8 | C9 | C10 | |
R1 | 10 | 10 | 10 | 10 | 10 | 10 | 10 | 10 | 10 | 10 |
R2 | 10 | 10 | 10 | 10 | 10 | 10 | 10 | 10 | 10 | 10 |
R3 | 10 | 10 | 10 | 10 | 10 | 10 | 10 | 10 | 10 | 10 |
R4 | 10 | 10 | 20 | 20 | 20 | 20 | 20 | 20 | 10 | 10 |
R5 | 10 | 10 | 20 | 20 | 20 | 20 | 20 | 20 | 10 | 10 |
R6 | 10 | 10 | 20 | 20 | 20 | 20 | 20 | 20 | 10 | 10 |
R7 | 20 | 20 | 30 | 30 | 30 | 30 | 30 | 30 | 20 | 20 |
R8 | 20 | 30 | 30 | 40 | 50 | 50 | 40 | 30 | 30 | 20 |
R9 | 30 | 40 | 50 | 50 | 50 | 50 | 50 | 50 | 40 | 30 |
R10 | 20 | 40 | 50 | 50 | 50 | 50 | 50 | 50 | 40 | 20 |
A theater seating chart is implemented as a table of ticket prices, like this above Write a program that asks users to pick either a seat or a price. When choosing seat, indicate the row and column for the location; when choosing the price, like computer find the first available price; mark the sold seats by changing the price to 0. When a user specifies a seat, make sure it is available. Use loop to determine whether continue to order or not. In each time, the seating chart should be displayed for user. When user stops ordering, your program should output the number of tickets ordered, and amount ordered.
PS- the program is being written in python language and our insturctor has told us to us elif
""" Author: Date: File Name: ticket_booking.py """ def print_seats(data): """ :param data: :return: """ print(" ", end="") for i in range(len(data[0])): print("{0:>3s}".format("C" + str(i + 1)), end=" ", sep="") for i, row in enumerate(data): print("\n{0:>3s}".format("R" + str(i + 1)), end=" ", sep="") for column in row: print("{0:>3s}".format(str(column)), end=" ", sep="") print() def menu(): print("1.Pick Seat") print("2.Pick Price") print("3.Quit") def book_by_seat(data, booked): """ :param data: :param booked: :return: """ while True: print_seats(data) row_number = int(input("Enter row number:")) col_number = int(input("Enter column number:")) if data[row_number - 1][col_number - 1] != 0: booked.append((row_number, col_number, data[row_number - 1][col_number - 1])) data[row_number - 1][col_number - 1] = 0 print("Your ticked booked successfully") else: print("This seat is already booked.") opt = input("Do you want choose another one?y/n:") if opt.lower() == "n": print_seats(data) break def book_by_price(data, booked): """ :param data: :param booked: :return: """ while True: print_seats(data) price = int(input("Enter Price:")) flag = True for i, row in enumerate(data): for j, col in enumerate(row): if col == price: data[i][j] = 0 booked.append(((i + 1), (j + 1), price)) flag = False print("Your ticked booked successfully") break if not flag: break if flag: print("No ticket available at this price") opt = input("Do you want choose another one?y/n:") if opt.lower() == "n": print_seats(data) break if __name__ == '__main__': table = [ [10, 10, 10, 10, 10, 10, 10, 10, 10, 10], [10, 10, 10, 10, 10, 10, 10, 10, 10, 10], [10, 10, 10, 10, 10, 10, 10, 10, 10, 10], [10, 10, 20, 20, 20, 20, 20, 20, 10, 10], [10, 10, 20, 20, 20, 20, 20, 20, 10, 10], [10, 10, 20, 20, 20, 20, 20, 20, 10, 10], [20, 20, 30, 30, 30, 30, 30, 30, 20, 20], [20, 30, 30, 40, 50, 50, 40, 30, 30, 20], [30, 40, 50, 50, 50, 50, 50, 50, 40, 30], [20, 40, 50, 50, 50, 50, 50, 50, 40, 20], ] booked_seat = [] while True: menu() option = int(input("Choose your option:").strip()) if option == 3: break elif option == 1: book_by_seat(table, booked_seat) elif option == 2: book_by_price(table, booked_seat) amount = 0 for ticket in booked_seat: amount += ticket[2] print("Total Number Of Ticket:", len(booked_seat)) print("Total Amount:", amount)
output: