15,789,698 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 23:00pm
Afzaal Ahmad Zeeshan 31-Jul-22 18:31pm
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]
Afzaal Ahmad Zeeshan 31-Jul-22 18:42pm
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

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Top Experts
Last 24hrsThis month
 Graeme_Grant 250 Rick York 120 Maciej Los 90 Dave Kreskowiak 50 CPallini 50
 Richard MacCutchan 1,480 Dave Kreskowiak 1,400 Maciej Los 735 Richard Deeming 733 CPallini 700

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900