我是从课堂上提供的伪代码中写出来的,我已经弄明白了其中的大部分。我遇到的唯一问题是它返回前5个“球”的重复数字,我根本不知道为什么。伪代码中我不确定的一行是:“如果该数字不在主数字序列中”。我是这样编码的:
if number != mainNumbers:
这可能是个问题,但我不知道如何编写代码
from random import *
def drawing():
balls=0
mainNumbers=[]
while balls < 5:
number=randint(1,69)
if number != mainNumbers:
mainNumbers.append(number)
balls = balls + 1
mainNumbers.sort()
pBall=randint(1,26)
return mainNumbers, pBall
def main():
print("This program simulates a user defined number of Powerball drawings\n")
runs = int(input("What's the total number of drawings? "))
print()
count = 1
while count <= runs:
balls, pBall = drawing()
print("Drawing: {0} - The numbers are: {1} and the Powerball is: {2}".format(count, balls, pBall))
count = count + 1
main()
目前没有回答
相关问题 更多 >
编程相关推荐