15,965,610 members
See more: , +
my question is how to create a loop for x lists, informing how many lists you would like, example 3, and in print it gives the result list 1=[0, -1.5, -3.0, -4.5, -6.0, - 7.5 , -9, 0, -10.5] list 2=[0, -1.5, -3.0, -4.5, -6.0, -7.5, -9.0, -10.5] list 3 =[0, -1.5, -3.0, -4.5, -6.0, -7.5, -9.0, -10.5]

What I have tried:

```u=0
car=3
list2 = [ ]
list2.append(0)
for j in range(car)

for i in range(3,10):
u+=(5/10)*-3
list2.append(u)

print(list2)```
Posted
Updated 31-Jul-22 22:00pm
And the problem is?
Rodrigo 2022 31-Jul-22 18:34pm
my question is how to create a loop for x lists, informing how many lists you would like, example 3, and in print it gives the result list 1=[0, -1.5, -3.0, -4.5, -6.0, - 7.5 , -9, 0, -10.5] list 2=[0, -1.5, -3.0, -4.5, -6.0, -7.5, -9.0, -10.5] list 3 =[0, -1.5, -3.0, -4.5, -6.0, -7.5, -9.0, -10.5]
You can just use this "3" in a for loop to iterate over this value. But the code that you are showing is doing something else. It is "starting" from "3", not "ending" on it.

## Solution 1

You need to create a new sub-list inside `list2` for each iteration of `car`, something like:
Python
```u=0
car=3
list2 = []
for j in range(car):
list2.append([]) # add a new sublist to list2

for i in range(3,10):
u += (5 / 10) * -3
list2[j].append(u) # append the number to the current sublist

print(list2)```

v2