Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Part 3 : In this part, you will add the user functionality to generate reports and recommend whether to buy, sell, or hold stock positions
Part :
In this part, you will add the user functionality to generate reports and recommend whether to
buy, sell, or hold stock positions in a particular sector. This recommendation is made by the
user after a sectors companies are displayed. To store these reports, you will use a second
dictionary, named reportdict, that will use the sector as its key and a tuple as its value that
contains the average stock price over the entire sector and the user's recommendation. You will
also create a userdefined function, printReport that takes in three arguments: sector, price,
recommendation. The recommendation argument will be an optional argument, which when
used will overload the output of printReport
Firstly, make a copy of py and rename it to py
Your
ppy program will accomplish the following:
Initialize a second dictionary named reportdict.
From your code in
ppy after the user selects a sector and the companies and their
stock prices are printed, calculate and display the average stock price for the sector.
After displaying the average stock price, prompt the user as to whether they should
"Buy", "Sell", or "Hold".
a If the user indicates "Buy" or "Sell", add a new entry into reportdict with the
selected sector as the key, and the value being a tuple of Average Stock Price,
recommendation
b If the user indicates to "Hold", add a new entry into reportdict with the selected
sector as the key, and value being a tuple of Average Stock Price, None
Create a user defined function, printReport with the arguments sector, price, and the
optional argument recommendation.
a recommendation should be defaulted to None
b By default, the function should print the sector name, and the current average
stock price.
c If recommendation is not None, overload the printReport function to print off
the sector name, the current average stock price, and the recommendation eg
"Buy" or "Hold"
d Note: In this case, a recommendation of None indicates that the user selected
"Hold" when generating a report.
Add another input option to your sector list, which will print any reports that have been
generated by the user
a This action can be accomplished by looping through reportdict
b There should be code that determines when reportdict is empty
Your "main menu" output should now look similar to this:
After generating a few reports, this should be the output when selecting to show reports:
To print generated reports, type "REPORTS"
To exit the program, type "EXIT"
Select a sector to see its companies and its current stock market price: REPORTS
Printing reports...
Sector: il Market Price: Recommendation: Buy
Sector: Finance Market Price: Recommendation: Sell
Sector: Auto Market Price:
Press enter to continue...
For the "Auto" sector, the option "Hold" was chosen. Hence no recommendation was printed.
This is part of the overloading for printReport
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