Question: write this in Pythom Code. In this assignment, we will apply lists, tuples, set and / or dictionaries to solve a problem with first -
write this in Pythom Code.
In this assignment, we will apply lists, tuples, set and or dictionaries to solve a problem with firstclass functions.
Imagine this scenario: A company individual buys shares of a stock at $ per share, then another of the
same stock at $ per share, and then sells shares at $ After the sale, taxes must be paid capital gains tax.
But what is the profit since two different prices were paid for the stock. Well, the IRS has a rule for this situation. It
is an assetmanagement and valuation method in which the assets in this case stocks bought first are sold first.
So we must sell all shares of the first batch for a sale amount of $$ x then of the shares from the
second batch, for a sale amount of $$ yielding a total sale amount of $ This assumes all the stocks
are from the same company. We made but we must pay tax at a rate of So the tax is $ and the take
home is $
We will write code to solve this problem. The best solution is one based on classes, but for now we will use our
collections. Later we can revisit this with classes and objects.
For our solution, we will do these calculations for arbitrary purchases and sales of shares of multiple companies.
Specifications
Present the user with a menu of three options:
o Buy B or b
o Sale S or s
o Print P or p
o Exit E or e
Do not assume the user will enter valid data.
o This means invalid entry for the menu, prices, stock quantity.
o Note When selling, you cannot sell more stock than you have! Keep that in mind.
If the user selects Buy, then prompt the user for the threeletter symbol, the quantity, and the price.
If the user selects Sale, then prompt the user for the threeletter symbol, if the symbol exists in those bought,
then prompt for the quantity sold and price. Make sure you do not sell more than the number of stocks
available.
o Display the number of units sold at each purchase price and the total amount for the sale, the tax, and
the total takehome. Use the example above as a test case. Your output should be formatted to two
decimal places.
If the user selects Print, then display the name of the stock along with all number of shares and the purchase
price. Remember, you may have multiple copies of the same share.
If the user selects Exit, then close the application.
You may use any number combinations of the data structures we have discussed in class.
Use userdefined methods for user input, validation, calculations, etc...
Do not forget the DocString Comment in your functions.
o Note Your menu should be in its own module and called from main
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
