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."
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.")
Comments
Leave a comment