我设定的任务是创建一个程序,帮助人们为抽奖选择随机数,我不知道从哪里开始。程序必须:
这就是我到目前为止所做的一切:
lines=int(input("how many lines would you like?"))
for i in range (0,lines):
import random
lotterynumbers = []
x = 0
while x < 6:
lotterynumbers.append(random.randint(1, 49))
x += 1
lotterynumbers.sort()
print (lotterynumbers)
请帮忙。
答案 0 :(得分:1)
在这里,这应该有所帮助:
from random import randint as rand_number
def create_lotter_numbers(amount=6):
return [rand_number(1,49) for i in range(amount)]
def get_user_input(prompt="how many lines would you like? "):
return int(input(prompt))
使用示例:
>>> a = get_user_input()
how many lines would you like? 5
>>> for i in range(a):
create_lotter_numbers()
[47, 22, 4, 7, 41, 16]
[12, 30, 36, 1, 39, 10]
[7, 19, 7, 13, 1, 17]
[5, 26, 9, 49, 32, 22]
[32, 30, 5, 34, 45, 6]
关于限制用户输入,重复,有效性等...您可以自己解决。这个答案就在这里,这样底层代码就像你发布的一样没有错误。