Question
You have decided to buy some stock in SBU Computing, Inc. The stock currently costs $32.87 per share. Your stockbroker charges a 2% commission for
You have decided to buy some stock in SBU Computing, Inc. The stock currently costs $32.87 per share. Your stockbroker charges a 2% commission for each transaction (meaning that he/she receives 2% of the total amount you pay for a stock purchase). A few weeks later, the stock price has risen to $33.92 per share, so you decide to sell all of your shares. Once again, your stockbroker earns a commission equal to 2% of the amount you receive for the stock. Will you make money or lose money on the deal?
For this problem, we will write a program that reads in the number of shares to purchase from the user. It then calculates and prints the total price paid for the stock shares, the broker's commission on the purchase, the price the stock shares were sold for, the broker's commission on the sale, and your ultimate profit (or loss) on the transaction.
a) We will begin by asking the user to enter the number of stock shares to purchase (assume that the user always enters an integer value, like 5; you can't buy a fraction of a share for this program!). To do this, we need to use the input command, and convert the result to an integer. Be sure to save the result (the user's input) into a variable!
shares = int( input("How many shares do you wish to purchase? ") )
B)Next, calculate the total cost of the shares of stock:
share_cost = shares * 32.87 Replace shares with whatever variable name you used for the previous step.
C) Our broker charges a 2% commission on any transaction. We can calculate this by multiplying the cost of the shares by 0.02:
commission1 = share_cost * 0.02
D) How much did we spend in all to buy the stock? That's just the cost of the shares plus the broker commission:
cost = share_cost + commission1
E)Add some print commands to print the results of the calculations from the previous steps.
F)Repeat the previous steps, with new variables, to calculate the amount of money we made by selling the stock at $33.92 per share. Don't forget that, this time, the broker's commission should be subtracted from our earnings!
G)Finally, calculate your final profit (or loss) by subtracting the price you initially paid from the amount you eventually made. Print this value with a descriptive message (a positive number indicates a profit, while a negative number indicates a loss).
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started