python 彩票摇奖
时间: 2023-11-17 08:04:21 浏览: 143
以下是一个简单的Python彩票摇奖程序,可以实现双色球和大乐透的摇奖功能:
```python
import random
def select_lottery():
print("请选择彩票种类")
print("双色球输入:1")
print("大乐透输入:2")
lottery_type = input("请输入:")
if lottery_type == "1":
red_balls = random.sample(range(1, 34), 6)
blue_ball = random.randint(1, 17)
print("红球:", end="")
for ball in sorted(red_balls):
print(ball, end=" ")
print("\n蓝球:", blue_ball)
elif lottery_type == "2":
red_balls = random.sample(range(1, 36), 5)
blue_balls = random.sample(range(1, 13), 2)
print("红球:", end="")
for ball in sorted(red_balls):
print(ball, end=" ")
print("\n蓝球:", end="")
for ball in sorted(blue_balls):
print(ball, end=" ")
print()
select_lottery()
```
运行程序后,会提示用户选择彩票种类,输入1表示双色球,输入2表示大乐透。程序会随机生成彩票号码,并输出到屏幕上。
阅读全文