简单电影院购票管理系统python代码实现
时间: 2024-12-19 12:01:46 浏览: 68
在Python中实现一个简单的电影院售票管理系统,我们可以创建一个命令行应用,包含用户登录、影片信息展示、购票、退票等功能。下面是一个基本的代码框架示例:
```python
class Movie:
def __init__(self, name, show_time, seats):
self.name = name
self.show_time = show_time
self.seats = seats
class Cinema:
def __init__(self):
self.movies = {} # 存储电影信息,如{'电影名': {'时间': 电影实例}...}
def add_movie(self, movie):
self.movies[movie.name] = movie
def display_movies(self):
for movie_name in self.movies:
print(f"{movie_name}: {self.movies[movie_name].show_time}")
def buy_ticket(self, movie_name, seat_number):
if movie_name in self.movies and self.movies[movie_name].seats > 0:
self.movies[movie_name].seats -= 1
print(f"Ticket for seat {seat_number} of {movie_name} purchased.")
else:
print("Sorry, no more tickets available.")
def refund_ticket(self, movie_name, seat_number):
if movie_name in self.movies and self.movies[movie_name].seats >= 0:
self.movies[movie_name].seats += 1
print(f"Refund completed for seat {seat_number} of {movie_name}.")
else:
print("No ticket to refund.")
cinema = Cinema()
# 添加电影信息
cinema.add_movie(Movie('电影A', '20:00', 50))
cinema.add_movie(Movie('电影B', '22:00', 70))
# 展示电影并购买和退款票
cinema.display_movies()
cinema.buy_ticket('电影A', 1)
cinema.refund_ticket('电影B', 3)
```
这个例子非常基础,实际的系统可能会更复杂,包括数据库操作、错误处理、用户界面等。使用类和方法模拟了影院的基本业务流程。
阅读全文