Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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?)

image text in transcribed

(result it should print)

image text in transcribed

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

image text in transcribed

(result i want)

image text in transcribed

(My Code)

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Application Development And Design

Authors: Michael V. Mannino

1st Edition

0072463678, 978-0072463675

More Books

Students also viewed these Databases questions

Question

=+b) Compute the x2 statistic.

Answered: 1 week ago

Question

Discuss the purpose and advantages of conducting a needs assessment

Answered: 1 week ago

Question

=+2 Why are international employment standards important to IHRM?

Answered: 1 week ago

Question

=+1 Why are local employment laws important to IHRM?

Answered: 1 week ago

Question

=+ Are some laws more important than others? If so, which ones?

Answered: 1 week ago