So my Problem is I have a list with number or strings d=[3050,1964,1250] Depending on the name 3050,1964 or 1250 the code needs to pick the right list. List [500,500,500,500,500,500] if 3050 or List [500,500,500,400] if 1964 or list [400,400,400] if 1250.
It also has to append/compile all the list togehter as sublist. So the Resulst would look like e=[[500,500,500,500,500,500],[500,500,500,400],[400,400,400]]
I have tried to wright a code below but it dose not work and I dont understand what to do. Please help
d=[3050,1964,1250]
e=[]
for i in d:
if i==3050:
calc=[500,500,500,500,500,500]
elif i==1964:
calc=[500,500,500,400]
else:
calc=[400,400,400]
e.append(calc)
CodePudding user response:
You can try this:
d=[3050,1964,1250]
e=[]
for i in d:
if i==3050:
calc=[500,500,500,500,500,500]
elif i==1964:
calc=[500,500,500,400]
else:
calc=[400,400,400]
e.append(calc)
You got the last line wrong, it doesn't align with the function above
CodePudding user response:
You have an indentation problem try this:
d=[3050,1964,1250]
e=[]
for i in d:
calc=[400,400,400]
if i==3050:
calc=[500,500,500,500,500,500]
elif i==1964:
calc=[500,500,500,400]
e.append(calc)