强力球彩票的python代码

2024-06-01 08:14:49 发布

您现在位置:Python中文网/ 问答频道 /正文

我不知道如何为下面的问题编写代码

Write a Python function, call it Powerball(), that will return a legitimate Powerball lottery number. Recall that a Powerball number consists of 5 random numbers from 1 to 69, followed by a random number, known as the Powerball, from 1 to 26. In returning the numbers, the first 5 numbers should be in order, followed by the Powerball. Here is an example: 4, 13, 31, 36, 52, 8. You may use a list to return the numbers, like [4, 13, 31, 36, 52, 8].


Tags: theto代码fromnumberbyreturnthat
1条回答
网友
1楼 · 发布于 2024-06-01 08:14:49

随机导入为r

def Powerball():
    result = []
    for i in range(5):
        number = r.randint(1,69)
        while (number in result):
            number = r.randint(1,69)
        result.append(number)
    result.sort()
    result.append(r.randint(1,26))
    return result

if __name__ == '__main__':
    result = Powerball()        
    print result

此代码按升序返回前5个从1到69的唯一随机数,后跟1到26的随机数。在

相关问题 更多 >