Question: Python. I did something wrong in my code and i'm not getting my desired result, help! (result im getting, why is profit in the negatives?)

Python. I did something wrong in my code and i'm not getting my desired result, help!

(result im getting, why is profit in the negatives?)

Python. I did something wrong in my code and i'm not getting

(result it should print)

my desired result, help! (result im getting, why is profit in the

(result im getting, idk why my profit is not negative and the decimal is so long)

negatives?) (result it should print) (result im getting, idk why my profit

(result i want)

is not negative and the decimal is so long) (result i want)

(My Code)

(My Code) Thanks in advance. Stock Unit Price DBS 3000 22.36 SIA

Thanks in advance.

Stock Unit Price DBS 3000 22.36 SIA 5000 4.23 DBS 5000 25.23 Singtel 4000 3.18 DBS 3000 23.23 Singtel 1000 2.78 SIA 3000 5.23 Singtel 2000 2.56 What stock do you want to sell ? DBS, 9000, 24.89 Your profit is -10870.0 What stock do you want to sell DBS, 9000, 24.89 ain Your profit is 7550.0 Your profit is 7480.000000000007 What stock do you want to sell? SIA, 9000,3.67 your holding of SIA is less than the number of units you want to sell. We will sell all your hold ng (8000) units for you. Your profit is -7480.0 f = open("stock.txt","2") name = stock1 = [] amt = [] for i in f: for j in i.split(','): if c3==0: name.append() elif c83==1: stocki.append(int(i)) else: amt.append(float(j)) C+=1 #stock details print("Your current holding is : ") print("Stock Unit Price") for i in range(0, len (name)): print(name[i], stocki[i], amt[i]) #asking user what stock to be sold print("What stock are you selling ? ") 1=list (map (str, input().split(','))) 1[1]=int (1[1]) 1 [2]=float(1[2]) #check whethere therea are stocks in comapany if 1[0] not in name: print("You do not hold any ",1[0]," stocks") #if user hold stocks else: indices = [] #find stocks of company for i in range (len (name)): if name[i] = 1[0]: indices.append(i) 3=0 for i in indices: 3+=Stocki[i] p=0 #not enough stocks if 1[1]): break 3=3*1 [2] pop-3 print("Your profit is ",p)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!