How can I create a list which contains only zeros? I want to be able to create a zeros list for each int in range(10)
For example, if the int in the range was 4 I will get:
[0,0,0,0] and for 7:
[0,0,0,0,0,0,0]
In Python, a list is created by placing elements inside square brackets [] , separated by commas.
#add code here to figure out the number of 0's you need, naming the variable n. listofzeros = [0] * n if you prefer to put it in the function, just drop in that code and add return listofzeros
Which would look like this:
def zerolistmaker(n): listofzeros = [0] * n return listofzeros sample output:
>>> zerolistmaker(4) [0, 0, 0, 0] >>> zerolistmaker(5) [0, 0, 0, 0, 0] >>> zerolistmaker(15) [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] >>>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With