Python 3.5乐透程序帮助(简单)

Python 3.5乐透程序帮助(简单),python,random,Python,Random,嗨,这是我下面的python 3.5乐透程序 import random one = (random.randint(1,40)) two = (random.randint(1,40)) three = (random.randint(1,40)) four = (random.randint(1,40)) five = (random.randint(1,40)) six = (random.randint(1,40)) seven = (random.randint(1,40)) #But

嗨,这是我下面的python 3.5乐透程序

import random
one = (random.randint(1,40))
two = (random.randint(1,40))
three = (random.randint(1,40))
four = (random.randint(1,40))
five = (random.randint(1,40))
six = (random.randint(1,40))
seven = (random.randint(1,40))
#But it's going to print duplicate numbers. How to fix?

print ("The winning lotto numbers this week are:", one, two, three, four, five, six,"and", seven,)

print (input("Press the enter key to exit"))
如何防止程序在结果中打印重复的数字


谢谢

您可以使用random.sample

import random

numbers = range(1, 41)
draw = random.sample(numbers, 7)
您可以使用该方法创建如下列表:

winners = random.sample(range(1,41), 7)
print ("The winning lotto numbers this week are: {}, {}, {}, {}, {}, {}, and {}".format(*winners))

这些答案有帮助吗?如果是,请按照回答进行投票和标记。