python实现双色球
·

import random
"""
双色球
"""
def chooseYourOwnNumber():
while True:
print("请输入6个红球号码(1-33)用空格隔开且不允许重复")
redStr = input()
redList = list(redStr.split())
# [sc for sc in scores if sc >= 60]
redList = [i for i in redList if 1 <= int(i) <= 33]
redSet = set(redList)
if len(redSet) != 6:
print("您输入的红球号码有重复或数量不够,请重新输入!!")
else:
while True:
print("请输入1个篮球号码(1-16)")
blueBall = input()
if 1 <= int(blueBall) <= 16:
break
else:
print("您输入的蓝球号码不符合规范,请重新输入!!")
redList.append(blueBall)
redList.sort()
return redList
def machineChooseNumber():
everyList = list(range(1, 34))
redList = []
for i in range(1, 7):
index = random.randint(0, len(everyList) - 1)
redList.append(everyList.pop(index))
blueBall = random.randint(1, 16)
redList.sort()
redList.append(blueBall)
return redList
def checkWin(winNumber, yourOwnNumber):
yourRedBall = [str(i) for i in yourOwnNumber[0:6]]
yourBlueBall = yourOwnNumber[6]
winRedBall = [str(i) for i in winNumber[0:6]]
winBlueBall = winNumber[6]
print("您的选择是: 红球:" + ",".join(yourRedBall) + " 蓝球: " + str(yourBlueBall))
print("中奖号码是: 红球:" + ",".join(winRedBall) + " 蓝球: " + str(winBlueBall))
yourRedBallSet = set(yourRedBall)
winRedBallSet = set(winRedBall)
sameRed = yourRedBallSet & winRedBallSet
if len(sameRed) == 6 and yourBlueBall == winBlueBall:
return 1
elif len(sameRed) == 6:
return 2
elif len(sameRed) == 5 and yourBlueBall == winBlueBall:
return 3
elif (len(sameRed) == 4 and yourBlueBall == winBlueBall) or (len(sameRed) == 5):
return 4
elif (len(sameRed) == 3 and yourBlueBall == winBlueBall) or (len(sameRed) == 4):
return 5
elif yourBlueBall == winBlueBall:
return 6
else:
return 0
def printWin(winNum):
match winNum:
case 0:
print("没有奖")
case 1:
print("一等奖 五千万")
case 2:
print("二等奖 三千万")
case 3:
print("三等奖 3000元")
case 4:
print("四等奖 200元")
case 5:
print("五等奖 10元")
case 6:
print("六等奖 5元")
while True:
print("*" * 25 + " 欢迎使用双色球系统 " + "*" * 25)
comment = input("请输入您的选择:1、自选号码 2、机选号码 0、退出系统 请输入:")
winNumber = machineChooseNumber()
match comment:
case "0":
break
case "1":
yourOwnNumber = chooseYourOwnNumber()
winNum = checkWin(winNumber, yourOwnNumber)
printWin(winNum)
case "2":
machineNumber = machineChooseNumber()
winNum = checkWin(winNumber, machineNumber)
printWin(winNum)
case _:
print("您输入的命令有误请重新输入!!!")
更多推荐

所有评论(0)