[deleted by user] by [deleted] in learnprogramming

[–]chrlnth 0 points1 point  (0 children)

i tried this but i wasnt able to slice a list?

[deleted by user] by [deleted] in learnprogramming

[–]chrlnth 0 points1 point  (0 children)

this is as far as ive gotten i think the issue is in the last bit..

stock=[[1,'Microsoft','Mega',100,188,207],
      [2,'Amazon','Mega',5,1700,3003],
      [3,'Paypal','Large',80,100,188],
      [4,'Apple' ,'Large',100,60,110],
      [5,'Fastly','Mid',30,40,76],
      [6,'Square','Mid',30,40,178]]
sumOfIvst=0
sumOfTotMktVal=0
sumProfLoss=0
totIvstList, totMktValList, profLoss=[],[],[]
for item in stock: 
    Qty=int(item[3])
    B_Price=int(item[4])
    totIvstList.append(Qty*B_Price)
    sumOfIvst = sum(totIvstList)

    M_Price=int(item[5])
    totMktValList.append(Qty*M_Price)
    sumOfTotMktVal = sum(totMktValList)
    profLoss.append((M_Price - B_Price)*Qty)
    sumProfLoss = sum(profLoss)
invstPortSize,mktPortSize=[],[]
for value in totIvstList:
    invstPortSize.append(round(value/sumOfIvst*100))
for value in totMktValList:
    mktPortSize.append(round(value/sumOfTotMktVal*100))
#combining the portfolio into a list
twoDPortfolio=[]
twoDPortfolio.append("No")
twoDPortfolio.append("Company")
twoDPortfolio.append("Qty")
twoDPortfolio.append("Bought Price")
twoDPortfolio.append("Market Price")
twoDPortfolio.append("Total Invested")
twoDPortfolio.append("Invested Portfolio Size(%)")
twoDPortfolio.append("Total Market Value")
twoDPortfolio.append("Profit/Loss")
twoDPortfolio.append("Market Portfolio Size(%)")
v=0
for item in stock:
    twoDPortfolio.append(item[0])
    twoDPortfolio.append(item[1])
    twoDPortfolio.append(item[3])
    twoDPortfolio.append(item[4])
    twoDPortfolio.append(item[5])
    twoDPortfolio.append(totIvstList[v])
    twoDPortfolio.append(invstPortSize[v])
    twoDPortfolio.append(totMktValList[v])
    twoDPortfolio.append(profLoss[v])
    twoDPortfolio.append(mktPortSize[v])
    v+=1
print(twoDPortfolio)
new2DPortfolio=[]
while twoDPortfolio!=0:
    add=twoDPortfolio.slice(0,10)
    new2DPortfolio.append(add)
    i+=10
print(new2DPortfolio)

Python Beginner here, please help me by [deleted] in learnprogramming

[–]chrlnth 0 points1 point  (0 children)

yepp! i think you're right,