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 |
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 2 images