Answered step by step
Verified Expert Solution
Link Copied!

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 3:
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 sector's companies are displayed. To store these reports, you will use a second
dictionary, named report_dict, 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 user-defined 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 p2.py and rename it to p3.py
Your
p3.py program will accomplish the following:
Initialize a second dictionary named report_dict.
From your code in
p2.py, 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 report_dict 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 report_dict 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 (e.g.
"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 report_dict
b. There should be code that determines when report_dict 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: 0il | Market Price: 125.02| Recommendation: Buy
Sector: Finance | Market Price: 30959.49| Recommendation: Sell
Sector: Auto | Market Price: 77.78
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().
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Administrator Limited Edition

Authors: Martif Way

1st Edition

B0CGG89N8Z

More Books

Students also viewed these Databases questions

Question

1. Does your voice project confidence? Authority?

Answered: 1 week ago