模拟双色球练手代码,求大神指点~
#声明:本人纯小白一枚~以下纯粹为自学练手代码,希望大神多多指教,Thanks♪(・ω・)ノ~# 生成双色球中奖号码的工具
#红球 1~33,篮球 1~16
from random import randint
def creat_num():
nums = []
for i in range(6):
# print(randint(1,33))
while True:
num = randint(1, 33)
if num not in nums:
nums.append(num)
break
blueball = randint(1, 16)
nums = sorted(nums)
nums.append(blueball)
return nums
#print(creat_num())
#判断是否中奖
def pan_duan(nums,buy_nums):
# nums=
# buy_nums=
redball=0
blueball=0
for i in buy_nums[:-1]: #判断红球中了多少个
if i in nums[:-1]:
redball+=1
if buy_nums[-1]==nums[-1]: #判断篮球是否中奖
blueball+=1
#判断中了几等奖?
"""
一等奖:6+1
redball==6 and blueball=1
二等奖:6+0
redball==6 and blueball=0
三等奖:5+1
redball==5 and blueball=1
四等奖:5+0 或 4+1
redball==5 and blueball=0orredball==4 and blueball=1
五等奖:4+0 或3+1
redball==4 and blueball=0orredball==3 and blueball=1
六等奖:2+1 或 1+1 或 0+1
redball==2 and blueball=1orredball==1 and blueball=1orredball==0 and blueball=1
"""
if redball==6 and blueball==1:
return 1
elif redball==6:
return 2
elif redball == 5 and blueball == 1:
return 3
elif (redball == 5 and blueball == 0) or (redball == 4 and blueball == 1):
return 4
elif (redball == 4 and blueball == 0) or (redball == 3 and blueball == 1):
return 5
elif (redball == 4 and blueball == 0) or (redball == 3 and blueball == 1) or blueball==1:
return 6
else:
#print("很遗憾,您未中奖!")
return 0
#print(f"您中了:{pan_duan()}等奖!")
nums=creat_num()
print("开奖号码为:",nums)
buy_nums=[1,2,7,12,26,29,2]
print("购买号码为:",buy_nums)
print(f"您中了:{pan_duan(nums,buy_nums)}等奖!") {:1_893:}佩服啊啊。话说,代码可以直接调用吗? 有点东西 恭喜中大奖 后面你还会再写至少一次的,相信我 现在都这么厉害的纯小白吗 dork 发表于 2022-10-16 18:41
后面你还会再写至少一次的,相信我
应该不止一次 O(∩_∩)O哈哈~ lwp72495lwp 发表于 2022-10-16 18:11
恭喜中大奖
一起中大奖 恭喜中大奖
天天中奖
页:
[1]
2