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

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

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

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
Transcribed Image Text: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
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
Transcribed Image Text: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
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY