Given the following code, I need help correcting it to follow these instructions using python (the csv file contains the following info...) Jan 14317 Feb 3903 Mar 1073 Apr 3463 May 2429 Jun 4324 Jul 9762 Aug 15578 Sep 2437 Oct 6735 Nov 88 Dec 2497
Given the following code, I need help correcting it to follow these instructions using python
(the csv file contains the following info...)
Jan | 14317 |
Feb | 3903 |
Mar | 1073 |
Apr | 3463 |
May | 2429 |
Jun | 4324 |
Jul | 9762 |
Aug | 15578 |
Sep | 2437 |
Oct | 6735 |
Nov | 88 |
Dec | 2497 |
#import the csv module for read-write
import csv
#file name for csv
FILE_NAME = "monthly_sales.csv"
#Show title of editor
def display_title():
print("FirstName LastName's Monthly Sales")
#space
print()
#show user menu display
def display_menu():
print("Command Menu\n\n Monthly - View monthly sales\n yearly - View yearly summary\n edit - Edit sales for a month\n exit - Exit program")
"""def read_sales():"""
#main function
def main():
sales = []
#write to the csv file
with open(FILE_NAME, "r", newline="") as file:
reader = csv.reader(file)
for row in reader:
sales.append(row)
#print out the display title and menu and then give user options to choose from
while True:
#show menu
display_title()
display_menu()
command = input("Command: ")
#begin of if loop
if command == "monthly":
view_monthly_sales(sales)
#show yearly
elif command == "yearly":
view_yearly_summary(sales)
#allow to edit
elif command == "edit":
edit(sales)
#exit program
elif command == "exit":
break
#give user error if invalid input is entered
else:
print("Not a valid command. Please try again.\n")
#allow user to know program is ended
print("Bye!")
view_monthly_sales(sales)
for row in sales:
print(f"{row[0]} - {row[1]}")
print()
view_yearly_summary(sales)
total = 0
for row in sales:
amount = int(row[1])
total += amount
# get count
count = len(sales)
# calculate average
average = total / count
average = round(average, 2)
# format and display the result
print("Yearly total: ", total)
print("Monthly average: ", average)
print()
#end of program
if __name__ == "__main__":
main()
Trending now
This is a popular solution!
Step by step
Solved in 3 steps