1.(模拟自助选票系统)现在放假看电影已经成为大家休闲娛乐的项日之一。每年的春节档电影院都会上映各种类型的电影,以供选择。下面编写程序模拟自助选票系统,输出选择的电影票信息,包括电影名称、观影时间和座位。 创建 Python 文件choose_ticket.py,编写以下程序。该程序定义类 ChooseTicket,里面封装了各种方法和属性。
时间: 2024-04-09 15:27:17 浏览: 10
Sure! Here's an example implementation of the ChooseTicket class in the choose_ticket.py file:
```python
class ChooseTicket:
def __init__(self, movie_name, show_time, seats):
self.movie_name = movie_name
self.show_time = show_time
self.seats = seats
def display_movie_info(self):
print("Movie: ", self.movie_name)
print("Show Time: ", self.show_time)
print("Available Seats: ", self.seats)
def select_seat(self, seat_number):
if seat_number in self.seats:
self.seats.remove(seat_number)
print("Seat", seat_number, "has been selected.")
else:
print("Seat", seat_number, "is not available.")
def book_ticket(self, seat_number):
if seat_number in self.seats:
self.seats.remove(seat_number)
print("Ticket booked for seat", seat_number)
print("Enjoy the movie!")
else:
print("Seat", seat_number, "is not available.")
```
This code defines a ChooseTicket class with properties like movie_name, show_time, and seats. It also contains methods to display movie information, select a seat, and book a ticket. You can create an instance of this class and interact with its methods to simulate a self-service ticketing system.