Create a python script following the below guidelines. I will enter my python starter script at the bottom under the requirements. I will also attach a screenshot of my excel file and desired outcome. This is an exercise I'm trying to understand. complete a program that reads the sales for 12 months from a file and calculates the total yearly sales as well as the average monthly sales. In addition, this program should let the user edit the sales for any month. Specifically, open the starter code given in monthly_sales_starter.pyfile. Read and understand the existing code –it has implemented the functions that handle printing welcome messages and the rules, and also the main function that handles the command loop. You are supposed to implement the following functions that either read/write data or perform one of the commands. Here’s what each function is supposed to do: 1.read_sales: Function to read contents of FILENAME and return the contents list of lists. Since csv returns string values for all columns, the function should convert the sales number (2nditem in each row) to integers. Use exception handling code so that if the file is not found, the function gives feedback that the file was not found and exits the program.(See sample run #2 below) 2.write_sales: Function to write the contents of sales, alist of lists, to FILENAME. 3.view_monthly_salesFunction accepts a list of lists with monthly sales values and prints the values of the monthly sales.(See sample run #1below) 4.view_yearly_summary: Function accepts a list of lists with monthly sales data, and prints the yearly summary of the sales values: yearly total and the monthly average sales.Print average using up to 2 decimal places.(See sample run #1below) 5.edit: Function accepts a list of lists with monthly sales values, and lets the user edit the sales data for one of the months. Specifically, a.promptsthe user for a 3-letter month code. Raises an exception if the user enters an invalid code. (See sample run #3below) b.promptsthe user for the new sales numbers as an integer. c.Use a try/except block that will handle invalid input cases, give user correct feedback and return. d.In case of valid input, program should update the csv file with new data. See the sample run below using the sample input csv file. ##my start code import csv import sys # a file in the current directory FILENAME = "monthly_sales.csv" def read_sales(): ''' Function to read contents of FILENAME and return the contents as a list of lists. If the file is not found, the function should give feedback that the file was not found and exit the program. Since CSV returns string values for all columns, the function should convert the sales number to integers.''' pass def write_sales(sales): ''' Function to write the contents of sales, a list of lists, to FILENAME.''' pass def view_monthly_sales(sales): ''' Function to print the values of the monthly sales. ''' pass def view_yearly_summary(sales): ''' Function to print the yearly summary of the sales values: it should print the yearly total and the monthly average sales.''' # helper list names = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'] pass def edit(sales): ''' Let the user edit the sales value for one of the months. - Prompt the user for a 3-letter month code. Raise an exception if the user enters an invalid code. - Prompt the user for the new sales numbers. - Use a try/except block that will handle invalid input in both cases. ''' pass def display_menu(): print("COMMAND MENU") print("monthly - View monthly sales") print("yearly - View yearly summary") print("edit - Edit sales for a month") print("exit - Exit program") print() def main(): print("Monthly Sales program") print() sales = read_sales() display_menu() while True: command = input("Command: ") if command == "monthly": view_monthly_sales(sales) elif command == "yearly": view_yearly_summary(sales) elif command == "edit": edit(sales) elif command == "exit": break else: print("Not a valid command. Please try again.\n") print("Bye!") if __name__ == "__main__": main() ##end of my code things called in main CSV/Excel doc
Create a python script following the below guidelines. I will enter my python starter script at the bottom under the requirements. I will also attach a screenshot of my excel file and desired outcome. This is an exercise I'm trying to understand.
complete a
Specifically, open the starter code given in monthly_sales_starter.pyfile. Read and understand the existing code –it has implemented the functions that handle printing welcome messages and the rules, and also the main function that handles the command loop. You are supposed to implement the following functions that either read/write data or perform one of the commands. Here’s what each function is supposed to do:
1.read_sales: Function to read contents of FILENAME and return the contents list of lists. Since csv returns string values for all columns, the function should convert the sales number (2nditem in each row) to integers. Use exception handling code so that if the file is not found, the function gives feedback that the file was not found and exits the program.(See sample run #2 below)
2.write_sales: Function to write the contents of sales, alist of lists, to FILENAME.
3.view_monthly_salesFunction accepts a list of lists with monthly sales values and prints the values of the monthly sales.(See sample run #1below)
4.view_yearly_summary: Function accepts a list of lists with monthly sales data, and prints the yearly summary of the sales values: yearly total and the monthly average sales.Print average using up to 2 decimal places.(See sample run #1below)
5.edit: Function accepts a list of lists with monthly sales values, and lets the user edit the sales data for one of the months. Specifically,
a.promptsthe user for a 3-letter month code. Raises an exception if the user enters an invalid code. (See sample run #3below)
b.promptsthe user for the new sales numbers as an integer.
c.Use a try/except block that will handle invalid input cases, give user correct feedback and return.
d.In case of valid input, program should update the csv file with new data.
See the sample run below using the sample input csv file.
##my start code
import csv
import sys
# a file in the current directory
FILENAME = "monthly_sales.csv"
def read_sales():
''' Function to read contents of FILENAME and return the contents as
a list of lists. If the file is not found, the function should give feedback that
the file was not found and exit the program.
Since CSV returns string values for all columns, the function should convert
the sales number to integers.'''
pass
def write_sales(sales):
''' Function to write the contents of sales, a list of lists, to
FILENAME.'''
pass
def view_monthly_sales(sales):
''' Function to print the values of the monthly sales.
'''
pass
def view_yearly_summary(sales):
''' Function to print the yearly summary of the sales values: it should print the
yearly total and the monthly average sales.'''
# helper list
names = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
pass
def edit(sales):
''' Let the user edit the sales value for one of the months.
- Prompt the user for a 3-letter month code. Raise an exception if the user enters an
invalid code.
- Prompt the user for the new sales numbers.
- Use a try/except block that will handle invalid input in both cases.
'''
pass
def display_menu():
print("COMMAND MENU")
print("monthly - View monthly sales")
print("yearly - View yearly summary")
print("edit - Edit sales for a month")
print("exit - Exit program")
print()
def main():
print("Monthly Sales program")
print()
sales = read_sales()
display_menu()
while True:
command = input("Command: ")
if command == "monthly":
view_monthly_sales(sales)
elif command == "yearly":
view_yearly_summary(sales)
elif command == "edit":
edit(sales)
elif command == "exit":
break
else:
print("Not a valid command. Please try again.\n")
print("Bye!")
if __name__ == "__main__":
main()
##end of my code things called in main
CSV/Excel doc
Jan | 14317 |
Feb | 5892 |
Mar | 1073 |
Apr | 3463 |
May | 2429 |
Jun | 4324 |
Jul | 9762 |
Aug | 15578 |
Sep | 2437 |
Oct | 6735 |
Nov | 88 |
Dec | 239 |
![IDLE Shell 3.9.2
File Edit Shel Debug Options Window Help
Monthly Sales program
COMMAND MENU
- View monthly sales
View yearly summary
- Edit sales for a month
- Exit program
monthly
yearly
edit
exit
Command: monthly
Jan -
14317
Feb - 5892
Mar - 1073
Apr - 3463
May - 2429
- 4324
- 9762
- 15578
Jun
Jul
Aug
Sep - 2437
Oct - 6735
Nov - 88
Dec - 239
Command: yearly
Yearly total:
Monthly average:
66337
5528.08
Command: edit
Three-letter Month: Apr
Sales Amount: 4100
sales amount for Apr was modified.
Command: yearly
Yearly total:
Monthly average:
66974
5581.17
Command: exit
Bye!
>>>
Ln: 42 Col: 4](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F535fabf5-596d-4dc5-9762-a0ef7f611594%2F84fed893-c441-4fba-8ddf-a059fca43f91%2Ffbprhz7_processed.png&w=3840&q=75)
![Sample Run #2: File not found
IDLE Shell 3.92
Eile Edit Shell Debug Options Window Help
Monthly Sales program
www ww
Could not find monthly_sales.csv file.
Exiting program. Bye!
>>>
>>> |
Ln: 49 Col: 4
Sample Run #3: Invalid input
IDLE Shell 3.92
Eile Edit Shell Debug Qptions Window Help
Monthly Sales program
wwwww ww
www
COMMAND MENU
monthly - View monthly sales
yearly
edit
View yearly summary
- Edit sales for a month
- Exit program
exit
Command: edit
Three-letter Month: Tmp
valueError:
Command: Feb
Invalid three-letter month.
Not a valid command. Please try again.
Command: thousand
Not a valid command. Please try again.
Command: exit
Вye!
>>>|
Ln: 119 Col](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F535fabf5-596d-4dc5-9762-a0ef7f611594%2F84fed893-c441-4fba-8ddf-a059fca43f91%2Fg3b63go_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 2 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Concepts of Database Management](https://www.bartleby.com/isbn_cover_images/9781337093422/9781337093422_smallCoverImage.gif)
![Prelude to Programming](https://www.bartleby.com/isbn_cover_images/9780133750423/9780133750423_smallCoverImage.jpg)
![Sc Business Data Communications and Networking, T…](https://www.bartleby.com/isbn_cover_images/9781119368830/9781119368830_smallCoverImage.gif)