-1

Take the list variable num1 = []

and say i also take num1_child = randint(0,100)

how do I go about making num1 progressively become a longer list by adding num1_child to the list, as opposed to simply changing it's value every eteration?

(I looked at: Adding integers progressively to a list but did not fully understand how to implement that in my code)

Divide05
  • 27
  • 5
  • How long do you want your ```num1``` to be ? You could just append ```num1_child``` to ```num1``` – Ram Jun 26 '21 at 11:23
  • 2
    Do you know about the `.append()` method of lists? – L3viathan Jun 26 '21 at 11:23
  • I'd call the list `num` or `nums` instead of `num1`, which would wrongly suggest it was a single number rather than a list. Also, rather than saying "adding" to a list, you mean "appending". – smci Jun 26 '21 at 11:27
  • 2
    @L3viathan @smci I did not know that was a thing! Thank you very much. I'll look up the documentation for `.append()` – Divide05 Jun 26 '21 at 11:30

1 Answers1

1

Let's say you want to add 10 nums into the list, then you can achieve by using simple looping. Also You can change to whatever number you want and specify the parameter in the range() method.

>>> for i in range(10):
    nums.append(random.randint(0, 100))

    
>>> nums
[45, 97, 67, 40, 6, 18, 85, 19, 18, 76]
>>> 
Daniel Hao
  • 4,922
  • 3
  • 10
  • 23