Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Part 2 : In this part, you will use a dictionary to store sector information about each company. Your code should read the companyList.txt file.

Part 2:
In this part, you will use a dictionary to store sector information about each company. Your code
should read the companyList.txt file. You will also use a dictionary that uses the company name
as a key and a tuple with its sector and stock price as the stored value.
Firstly, copy
p1.py and rename the copy to p2.py
Your
p2.py program will accomplish the following:
Initialize an empty dictionary, named company_dict
Populate the dictionary with the companies found in companyList.txt, using the company
name as a key and the value as a tuple of (Sector, Stock Price)
a. For example: {Ford: (Auto","12.00"), Google: (Software","139.95"),...}
The user will be presented the number of unique sectors listed. The user will then
prompt to enter a number that corresponds to a given sector, or to exit the program.
a. Your program should re-prompt the user for an invalid number input (e.g., greater
than 9 or less than 1).
b. Your program does not need to implement edge cases for non-number inputs
When the user selects a sector, the companies that are attached to that sector and their
stock price will be displayed.
Your new "main menu" output should look something like this:
Welcome to the Generic Finance App!
There are 9 sectors,50 companies
1: Finance (5)
2: Semiconductor (5)
3: Software (5)
4: Conglomerate (6)
5: Retail (4)
6: Defense (7)
7: 0il (5)
8: Auto (7)
9: FMCG (6)
To exit the program, type "EXIT"
select a sector to see its companies and its current stock market price:
The menu includes a list of all sectors followed by a request for a choice input.
Use the entered number to identify the selected sector. Search through the dictionary and print
out all companies associated with the sector. Your output should appear as follows:
To exit the program, type "EXIT"
select a sector to see its companies and its current stock market price: 8
Selected sector: Auto
GM | stock: 36.82
Ford | stock: 12.00
Toyota | stock: 187.86
Tesla | stock: 239.90
Stellantis | stock: 22.67
Volkswagen | stock: 13.30
Honda | stock: 31.93
Press enter to continue...
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

Beginning Databases With PostgreSQL From Novice To Professional

Authors: Richard Stones, Neil Matthew

2nd Edition

1590594789, 978-1590594780

More Books

Students also viewed these Databases questions

Question

How is return on assets related to investing decisions?

Answered: 1 week ago