帮我用Python写一个彩票中奖程序
时间: 2023-03-26 15:02:32 浏览: 112
详解用python写一个抽奖程序
你好,我是 CSDN 开发的 C 知道,我可以回答你的问题。以下是 Python 编写的彩票中奖程序:
```python
import random
# 生成中奖号码
winning_numbers = []
while len(winning_numbers) < 6:
number = random.randint(1, 33)
if number not in winning_numbers:
winning_numbers.append(number)
winning_numbers.sort()
# 生成特别号码
special_number = random.randint(1, 16)
# 输入用户选择的号码
user_numbers = []
while len(user_numbers) < 6:
number = int(input("请输入一个1-33之间的数字:"))
if number < 1 or number > 33:
print("输入错误,请重新输入!")
elif number in user_numbers:
print("您已经输入过这个数字,请重新输入!")
else:
user_numbers.append(number)
user_numbers.sort()
# 判断中奖情况
matched_numbers = set(winning_numbers) & set(user_numbers)
matched_count = len(matched_numbers)
if matched_count == 6:
print("恭喜您中了一等奖,奖金为100万元!")
elif matched_count == 5 and special_number in user_numbers:
print("恭喜您中了二等奖,奖金为500万元!")
elif matched_count == 5:
print("恭喜您中了三等奖,奖金为300万元!")
elif matched_count == 4:
print("恭喜您中了四等奖,奖金为200元!")
elif matched_count == 3:
print("恭喜您中了五等奖,奖金为10元!")
else:
print("很遗憾,您没有中奖。")
print("中奖号码为:", winning_numbers)
print("特别号码为:", special_number)
print("您选择的号码为:", user_numbers)
```
希望这个程序能够帮到你!
阅读全文