|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
萌新求大佬们帮帮忙。有一道题说的是模拟购买大乐透中奖号码,然后查看自己买的号码和随机的中奖号码有几个是对应的,中了不同的几个数字需要print出不同的话。1. 想知道如何做到随机中奖号码不会重复;2. 如何用自己的号码去和中奖号码匹配啊?是一个一个按顺序验证吗?
这是我目前写出来的代码,实在是不知道该怎么继续了,求大佬解惑。
- import random
- print("Buy a ticket with 5 white balls [not identical, between 1-69] and 1 red ball [between 1-26]")
- a = int(input("Your first number for white balls\n"))
- b = int(input("Your second number for white balls\n"))
- c = int(input("Your third number for white balls\n"))
- d = int(input("Your forth number for white balls\n"))
- e = int(input("Your fiveth number for white balls\n"))
- f = int(input("Your number for red ball\n"))
- white1 = random.sample(range(1, 69), 1)
- white2 = random.sample(range(1, 69), 1)
- white3 = random.sample(range(1, 69), 1)
- white4 = random.sample(range(1, 69), 1)
- white5 = random.sample(range(1, 69), 1)
- red = random.randint(1, 26)
- print("Your selection for white balls are: ", a, b, c, d, e, )
- print("Your selection for red balls is: ", f )
- print("Winning numbers for white balls:", white1, white2, white3, white4, white5)
- print("Winning number for red ball:", red)
复制代码
以下是兑奖条件,if之后该写什么啊
if
print ("No matching. Thanks for your contribution!")
if
print ("Matching only the red ball: $4")
if
print ("Matching the red ball and one white ball: $4")
if
print ("Matching the red ball and two white balls: $7")
if
print ("Matching three white balls: $7")
if
print ("Matching the red ball and three white balls: $100")
if
print ("Matching four white balls: $100")
if
print ("Matching the red ball and four white balls: $10,000")
if
print ("Matching five white balls: $1,000,000")
if
print ("Matching five white balls and the red ball: Jackpot")
- import random
- print("Buy a ticket with 5 white balls [not identical, between 1-69] and 1 red ball [between 1-26]")
- mywhite = [int(input("Your first number for white balls\n")),
- int(input("Your second number for white balls\n")),
- int(input("Your third number for white balls\n")),
- int(input("Your forth number for white balls\n")),
- int(input("Your fiveth number for white balls\n"))]
- myred = int(input("Your number for red ball\n"))
- white = [random.randint(1, 69) for i in range(5)]
- red = random.randint(1, 26)
- print("Your selection for white balls are: ", *mywhite )
- print("Your selection for red balls is: ", myred )
- print("Winning numbers for white balls:", *white)
- print("Winning number for red ball:", red)
- matchwhite = 0
- for i, j in zip(mywhite, white):
- if i == j:
- matchwhite += 1
- matchred = 1 if myred == red else 0
- if matchwhite == 0 and matchred ==0:
- print ("No matching. Thanks for your contribution!")
- elif matchred:
- if matchwhite == 0:
- print ("Matching only the red ball: $4")
- elif matchwhite == 1:
- print ("Matching the red ball and one white ball: $4")
- elif matchwhite == 2:
- print ("Matching the red ball and two white balls: $7")
- elif matchwhite == 3:
- print ("Matching the red ball and three white balls: $100")
- elif matchwhite == 4:
- print ("Matching the red ball and four white balls: $10,000")
- else:
- print ("Matching five white balls and the red ball: Jackpot")
- else:
- if matchwhite == 3:
- print ("Matching three white balls: $7")
- elif matchwhite == 4:
- print ("Matching four white balls: $100")
- else:
- print ("Matching five white balls: $1,000,000")
复制代码
|
|