Programming Exercise 3

  < Previous  Next >

Due Date

See the calendar for due date.

Assignment:

Your program should calculate your net gain or loss during a stock transaction based on the number of shares, purchase price of the stocks, and the sale price. Ask the user for the number of shares purchased and the purchase price (per share). You pay your stockbroker a flat commission of $6.95 to purchase the shares. Later, you sell the all of the stocks. Ask the user for the selling price (per share). Additionally, the stockbroker gets an additional flat commission of $6.95 for selling the shares.

To calculate the profitability of a stock purchase, you first calculate how much it cost to purchase the stock (the number of shares times the price per share plus the commission). This is called the cost basis. Then, you calculate how much you got back after you sold the stock (the number of shares times the sale price per share, minus the commission). For example, if you purchased 5 shares of stock at $100.00 per share, your cost basis is the cost of the stock plus the commission: $506.95. If you sell the stock (all 5 shares) at $200.00 per share, you'd get $1,000 minus the $6.95 commission: $993.05, but remember it cost $506.95 to buy the stock, so the profitability is $486.10. (See the first example below).


If your transaction was profitable (or if there was a net gain/loss of $0.00) print:
After the transaction, you made $#.##.
If your transaction was not profitable, print:
After the transaction, you lost $#.##.

Examples

The following is an example of correct execution (with the text in bold being the input from the user):
Please enter the purchase price (per share): 100 
Please enter the number shares purchased: 5
Please enter the sale price (per share): 200
After the transaction, you made $486.10
Please enter the purchase price (per share): 16.73 
Please enter the number shares purchased: 3
Please enter the sale price (per share): 27.70
After the transaction, you made $19.01
Please enter the purchase price (per share): 46.99 
Please enter the number shares purchased: 2
Please enter the sale price (per share): 33.68
After the transaction, you lost $40.52
After completing the program and testing the output for accuracy, make sure that you have a comment lines at the top of your file with your name, course and section, current date, and assignment description.

Submission

Submit your python script using the handin program. For handin, for this lab, type the following in a terminal window exactly as it appears:
handin  pe3  pe3.py
To verify your submission, type the following in a terminal window:
handin  pe3

Optional

Made the output match exactly (meaning every character is the same) to the examples above.