用python写一个对会议室座位进行抽奖,并显示座位图,中奖座位变色显示,人工按停的的程序
时间: 2023-02-20 10:03:18 浏览: 95
详解用python写一个抽奖程序
以下是一个简单的示例代码:
```
import random
seats = ['A1', 'A2', 'A3', 'A4', 'A5', 'B1', 'B2', 'B3', 'B4', 'B5']
def display_seats(seats):
for i in range(0, len(seats), 5):
row = seats[i:i+5]
print(' '.join(row))
def draw_lottery(seats):
lucky_seat = random.choice(seats)
print("幸运座位是:" + lucky_seat)
return lucky_seat
display_seats(seats)
while True:
input_str = input("按回车键开始抽奖,输入'q'退出:")
if input_str.strip().lower() == 'q':
break
lucky_seat = draw_lottery(seats)
seats[seats.index(lucky_seat)] = '\033[1;32m' + lucky_seat + '\033[0m'
display_seats(seats)
```
在运行时,每次按回车键会进行一次抽奖,并显示座位图。中奖座位会变成绿色显示。输入'q'以退出程序。
阅读全文