Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Thank you Programming Exercises 79 12. Stock Transaction Program Last month Joe

ID: 3784001 • Letter: T

Question


Thank you Programming Exercises 79 12. Stock Transaction Program Last month Joe purchased some stock in Acme Software, Inc. Here are the details of the purchase The number of shares that Joe purchased was 2,000. When Joe purchased the stock, he paid $40.00 share. amount he Joe his stockbroker a commission that amounted to 3 percent of the paid for the stock. Two weeks later Joe sold the stock. Here are the details of the sale: The number of shares that Joe sold was 2,000 He sold the stock for $42.75 per share. to 3 percent of the amount He paid his stockbroker another commission that amounted he received for the stock Write a program that displays the following information: The amount of money Joe paid for the stock. when he bought the stock. The amount of commission Joe paid his broker The amount that Joe sold the stock for. stock. The amount of commission Joe paid his broker when he sold the stock and paid his Display the amount of money that Joe had left when he sold the If the amount is broker (both times). If this amount is positive, then Joe made a profit. negative, then Joe lost money.

Explanation / Answer

CODE:

print("********Stock Transaction Program*******")

noOfShare = 1000
paidPerShare = 40.0

paidOnShares = noOfShare * paidPerShare

print "Total amount was paid by Joe on 1000 shares was : $"+ str(format(paidOnShares ,'.2f'))
  
brokerCommission1 = paidOnShares * .03

print "Ccommission Joe paid when he bought the stock was : $" + str(format(brokerCommission1 , ',.2f'))

print(' ')

#After two weeks..
noOfShareSold = 2000
soldPerShare = 42.75
totalAmountSold = noOfShareSold * soldPerShare
balanceAmountBeforeCommission = totalAmountSold - ( paidOnShares + brokerCommission1)
print "Total amount Joe sold the stock for: $"+ str(format(totalAmountSold ,'.2f'))
print "Amount of money left with Joe before paying commission: $"+str(format(balanceAmountBeforeCommission , ',.2f'))

brokerCommission2 = totalAmountSold * .03
print "Amount of commission Joe paid when he sold the stock was: $" + str(format(brokerCommission2 , ',.2f'))

balanceAmountAfterCommission = totalAmountSold - ( paidOnShares + brokerCommission1 + brokerCommission2 )

print "Amount of money left with Joe after paying the commission: $"+str(format(balanceAmountAfterCommission , ',.2f'))

if(balanceAmountAfterCommission > 0):
print "Joe made a profit"
else:
print "Joe made a loss "

OUTPUT:

>> python joe,py

********Stock Transaction Program*******
Total amount was paid by Joe on 1000 shares was : $40000.00
Ccommission Joe paid when he bought the stock was : $1,200.00

Total amount Joe sold the stock for: $44300.00
Traceback (most recent call last):
File "joe.py", line 22, in <module>
print "Amount of money left with Joe before paying commission: $"+str(format(balanceAmount , ',.2f'))
NameError: name 'balanceAmount' is not defined

C:UsersAdminDesktop>python joe.py
********Stock Transaction Program*******
Total amount was paid by Joe on 1000 shares was : $40000.00
Ccommission Joe paid when he bought the stock was : $1,200.00

Total amount Joe sold the stock for: $85500.00
Amount of money left with Joe before paying commission: $44,300.00
Amount of commission Joe paid when he sold the stock was: $2,565.00
Amount of money left with Joe after paying the commission: $41,735.00
Joe made a profit

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote