Answer to Question #306720 in Python for jess

Question #306720

You decide to buy some stocks for a certain price and then sell them at another

price. Write a program that determines whether or not the transaction was

profitable.

• Take 3 separate inputs: the # of shares, the purchase

price of the stocks, and the sale price, in that order.

• You purchase the # of stocks determined by the input.

• When you purchase the stocks, you pay the price determined by the input.

• You pay your stockbroker a commission of 3% on the amount paid for

the stocks.

• Later, you sell the all of the stocks for the price determined by the input.

• You pay your stockbroker another commission of 3% on the amount

you received for the stock.


Your program should calculate your net gain or loss during this transaction and

print it in the following format:


If your transaction was profitable (or if there was a net gain/loss of 0) print:

"After the transaction, you made 300 dollars."


If your transaction was not profitable, print:

"After the transaction, you lost 300 dollars."



1
Expert's answer
2022-03-06T04:49:55-0500
number_of_shares = float(input("Enter the number of shares you want to buy: "))
price_to_buy = (float(input("The price of the shares in dollar: ")) * 0.97)
price_to_sell = float(input("The price you want to sell in dollar: "))


gain_or_loss = ((price_to_sell * number_of_shares) - (price_to_buy * number_of_shares))


if(gain_or_loss >= 0):
    print("After the transaction, you made " + str(gain_or_loss) + " dollars.")
else:
    print("After the transaction, you made " + str(gain_or_loss) + "dollars.")

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS