Skip to content

Commit a5ac64e

Browse files
authored
Stock Transaction Program ,Tony Gaddis (Chapter 2)
1 parent 0d4f730 commit a5ac64e

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

2.12. Stock Transaction.py

+50
Original file line numberDiff line numberDiff line change
@@ -1 +1,51 @@
1+
"""
2+
12. Stock Transaction Program
3+
Last month Joe purchased some stock in Acme Software, Inc. Here are the
4+
details of the purchase:
5+
- The number of shares that Joe purchased was 2,000.
6+
- When Joe purchased the stock, he paid $40.00 per share
7+
- Joe paid his stock broker a commission that amounted to 3% of the amount he
8+
paid for the stock
9+
Two weeks later Joe sold the stock. Here are the details of the sale:
10+
- The number of shares that Joe sold was 2,000.
11+
- He sold the stock for $42.75 per share
12+
- He paid his stockbroker another commission that amounted to 3 percent
13+
of the amount he received for the stock
14+
Write a program that displays the following information:
15+
The amount of money Joe paid for the stock.
16+
The amount of commission Joe paid his broker when he bought the stock.
17+
The amount that Joe sold the stock for.
18+
The amount of commission Joe paid his broker when he sold the stock.
19+
Display the amount of money that Joe had left when he sold the stock
20+
and paid his broker(both times).
21+
If this amount is positive, then Joe made a profit.
22+
If the amount is negative, then Joe lost money.
23+
Reference:
24+
(1) Starting out with Python, Third Edition, Tony Gaddis Chapter 2
25+
(2) https://youtu.be/t6MV_A54IkI
26+
"""
27+
# let store the values in variable
28+
number_of_share_purchased = 2000
29+
amount_paid_per_share = 40.00
30+
# Calculate the amount paid per stock
31+
amount_paid_per_stock = number_of_share_purchased * amount_paid_per_share
32+
# Calculate the commission for buying
33+
commission_for_buying = 0.03 * amount_paid_per_stock
34+
number_of_share_sold = 2000
35+
amount_sold_per_share = 42.75
36+
# Calculate the amount he received for the stock
37+
amount_received_per_stock = number_of_share_sold * amount_sold_per_share
38+
# Calculate the commission for sold
39+
commission_for_sold = 0.03 * amount_received_per_stock
40+
# Calculate the profit
41+
profit = amount_received_per_stock - commission_for_sold \
42+
- amount_paid_per_stock - commission_for_buying
143

44+
# displays the information
45+
print("Amount Paid for stock : $" + format(amount_paid_per_stock, ",.2f") , \
46+
"Commission for buying : $" + format(commission_for_buying, ",.2f") , \
47+
"Amount received per stock : $" + \
48+
format(amount_received_per_stock, ",.2f"),
49+
"Commission for selling : $" + \
50+
format(commission_for_sold, ",.2f"),\
51+
"profit : $" + format(profit, ",.2f") , sep = "\n")

0 commit comments

Comments
 (0)