- 1st Jul 2024
- 17:49 pm
A retail sales company has 3 branches (1, 2 and 3). The company’s manager would like to see a report about their monthly profit in each branch. You are required to write Python functions to accomplish this task. Each branch keeps daily records in a sales_BranchID.csv file at the head branch. These files contain lines that represent each day’s total sale amount, and total cost amount as shown in the example below. Each of the 3 files can contain a maximum of 30 lines.
- Write a function that accepts a Branch_ID (1,2, or 3), then reads all the lines inside the corresponding sales_BranchID.csv (e.g. sales_1.csv) into two dictionaries: sales_dict={day:sales} and cost_dict={day:cost}. Return both dictionaries. Use exception handling for any file errors.
- Write a function that accepts both dictionaries (sales_dict and cost_dict) of one branch as well as a start day number and end day number representing a range of days (e.g. 1-15). Calculate the total profit of that branch over this date range where total_profit = ∑??(sales-cost)? . Raise a ValueError exception if the total profit is negative. Return the total profit.
- Write a function that accepts the 3 sales dictionaries and a day number and prints to the screen the branch ID with the minimum sales amount on that day.
- Write a main function to test all of your functions.
Software Dev. and Problem Solving - GCIS123 - Get Assignment Solution
Please note that this is a sample Software Dev. and Problem Solving assignment solved by our Python Programmers. These solutions are intended to be used for research and reference purposes only. If you can learn any concepts by going through the reports and code, then our Python Tutors would be very happy.
- Option 1 - To download the complete Software Dev. and Problem Solving solution along with Code, Report and screenshots - Please visit our Python Assignment Sample Solution page
- Option 2 - Reach out to our Python Tutors to get online tutoring related to this assignment and get your doubts cleared
- Option 3 - You can check the partial solution for this assignment in this blog below
Free Assignment Solution - Software Dev. and Problem Solving - GCIS123
import csv
# this function reads file into a dictionaries and return it
def read_file_to_dictionary(branch_id):
file_name = 'sales_'+str(branch_id)+'.csv' # creating file name
try:
sales_dict = {}
cost_dict = {}
file = open(file_name)
csvreader = csv.reader(file) # reading the file
header = next(csvreader)
for row in csvreader:
sales_dict[int(row[0])] = int(row[1])
cost_dict[int(row[0])] = int(row[2])
file.close() # closing the file
return sales_dict, cost_dict # retuning the dictionary
except: # if file is not
print('File not exists')
# this function returns the profit
def get_total_profit(sales_dict, cost_dict):
sales = 0
cost = 0
for key in sales_dict:
sales = sales + sales_dict[key] # calculating total sales
for key in cost_dict:
cost = cost + cost_dict[key] # calculating total cost
profit = sales - cost # calculating profit
try:
if profit < 0: # checking if the profit is negative
raise ValueError
return profit # return the profit
except ValueError: # if the profit is negative
print('Profit is negative')
def get_minimum_sale_day(sales_dict_1,sales_dict_2,sales_dict_3,day):
# finding the sales of dictionary of particular day
sale_1 = sales_dict_1[day]
sale_2 = sales_dict_2[day]
sale_3 = sales_dict_3[day]
# finding the minimum sales
if sale_1 < sale_2 and sale_1 < sale_3:
print("Minimum Sales:",sale_1)
elif sale_2 < sale_3:
print("Minimum Sales:",sale_2)
else:
print("Minimum Sales:",sale_3)
def main():
# tetsing read_file_to_dictionary function
sales_dict, cost_dict = read_file_to_dictionary(1)
print(sales_dict)
print(cost_dict)
# tetsing get_total_profit function
profit = get_total_profit(sales_dict, cost_dict)
print(profit)
# testing minumum sale day
sales_dict_1 = {1: 15000, 2: 22435, 3: 10120}
sales_dict_2 = {1: 12000, 2: 25000, 3: 11120}
sales_dict_3 = {1: 13000, 2: 22000, 3: 17120}
get_minimum_sale_day(sales_dict_1, sales_dict_2, sales_dict_3, 2)
main()
Get the best Software Dev. and Problem Solving assignment help and tutoring services from our experts now!
About The Author - Alex Martinez
Alex Martinez, an experienced Python developer with a focus on data analysis and automation, will guide you through this retail sales project. Alex's expertise in handling real-world data ensures you will learn effective techniques for managing and analyzing sales data. In this project, Alex will help you write Python functions to read sales data, calculate profits, and identify branches with the minimum sales, providing a comprehensive approach to reporting and data handling in Python.