简体   繁体   English

Python彩票生成器我正在尝试弄清楚如何添加数字输入,并将它们分隔成行,并且为x数量的num long

[英]Python Lottery generator I'm trying to figure out how to add a number input, and separate them on lines and be x amount of num long

# Lottery Generator
def lotto():
    import random
    integer = []
    for number in range(0,5):
        integer.append(random.randint(1,101))
    return integer

print (lotto())

This is what I have so far. 到目前为止,这就是我所拥有的。 Not I try to input a number. 不,我尝试输入数字。 I can input a number and multiply it within the method, by using 我可以输入一个数字,并在方法中将其乘以

numInput = int(input("How many number sets do you need? "))

and adding that to the end 并将其添加到最后

print(lotto() * numInput)

but then it just gives me a number. 但这只是给我一个数字。 What I'm trying to get is something like this 我想要得到的是这样的

[5, 54, 84, 100, 72]
[16, 31, 95, 47, 10]

...etc. ...等等。 I want to print the output of lotto for numInput times. 我想将lotto的输出打印numInput次。

You need to loop over the amount of times inputted for numInput 您需要遍历为numInput输入的时间

def lotto():
    import random
    integer = []
    for number in range(0,5):
        integer.append(random.randint(1,101))
    return integer

numInput = int(input("How many number sets do you need? "))

for i in range(0, numInput):
    print (lotto())

If you would like to change the number of results returned per set. 如果要更改每组返回的结果数。 Then your function can accept an argument. 然后,您的函数可以接受参数。 For instance if you wanted 10 results per set. 例如,如果您希望每组10个结果。

def lotto(numbers):
    import random
    integer = []
    for number in range(0,numbers):
        integer.append(random.randint(1,101))
    return integer

numInput = int(input("How many number sets do you need? "))

for i in range(0, numInput):
    print (lotto(10))

Have your function take in a variable and then run a loop inside your function that appends that many of your lottery sets to a list and then return that list! 让您的函数接受一个变量,然后在函数内部运行一个循环,该循环将您的许多彩票集附加到列表中,然后返回该列表!

import random
def lotto(repetitions):
    lista = []
    for i in range(repetitions):
        integer = []
        for number in range(0,5):
            integer.append(random.randint(1,101))
        lista.append(integer)
    return lista

number = int(input("How many sets: "))
print(lotto(number))
 (xenial)vash@localhost:~/python/stack_overflow$ python3.7 lotto.py How many sets: 3 [[45, 99, 74, 64, 60], [65, 86, 51, 35, 93], [60, 4, 69, 14, 60]] 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我正在试图弄清楚如何将括号和短划线插入到作为输出的电话号码。 我正在使用python 3.5 - I'm trying to figure out how to insert parentheses and a dash to a phone number that is the output. I'm using python 3.5 我试图弄清楚如何在 python 上安装这个库(时间) - I'm trying to figure out how to install this lib on python (time) 我试图弄清楚如何添加到字典列表中,而不是创建一个字典列表列表 - I'm trying to figure out how to add to a list of dictionaries, rather than create a list of lists of dictionaries 我正在尝试找出Python中的简单列表加密 - I'm trying to figure out simple list encryption in Python 如何从用户输入中添加 X 数量,然后在 python 中添加所有数字? - How to add X amount number from user input then add all of number in python? 我是 python 的新手,我想弄清楚如何在同一行上一次打印一个字母 - I'm new to python and I am trying to figure out how to print letters one at a time on the same line 我试图弄清楚如何计算在Python的字符串句子中字母大写的次数 - I'm trying to figure out how to count how many times a letter is capitalized in a string sentence in Python 我试图弄清楚如何让python将歌词简单地发布到歌曲中 - I'm trying to figure out how to get python to simply post the lyrics to a song Python 3:我正在尝试将数字转换为零 - Python 3: I'm trying to transfer a number to an amount of zero's 我试图弄清楚如何以 2 的幂为循环递增 - I'm trying to figure out how increment for loop in powers of 2
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM