I need a simple python code
Brewster’s Used Cars, Inc. employs several salespeople.
Brewster, the owner of the company, has provided a file that
contains sales records for each salesperson for the past month.
Each record in the file contains the following two fields: The
salesperson’s ID number, as an integer
The amount of a sale, as a real number
The records are already sorted by salesperson ID. Brewster wants you to develop a program that prints a sales report. The report should show each salesperson’s sales and the total sales for that salesperson. The report should also show the total sales for all salespeople for the month. Here is an example of how the sales report should appear:
Brewster's Used Cars, Inc.Sales Report
Salesperson ID Sale Amount
====================================================
100 $10,000.00 100 $12,000.00 100 $5,000.00 Total sales for this salesperson:$27,000.00 101 $14,000.00 101 $18,000.00 101 $12,500.00 Total sales for this salesperson: $44,500.00 102 $13,500.00 102 $14,500.00 102 $20,000.00 Total sales for this salesperson: $48,000.00 Total of all sales: $119,500.00
the text file should look like this
100 10000
100 12000
100 5000
101 14000
101 18000
101 12500
102 13500
102 14500
102 20000
# do comment if any problem arises
# Code
# converts given number to international format
def international_format(number):
return ("{:,}".format(number))
# read name of file
filename = input("Enter filename: ")
# open file in read mode
file = open(filename, "r")
# read data from file
all_data = file.read().split("\n")
current_id = None
current_total = 0
total=0
print("Brewster's Used Cars, Inc.Sales Report")
print("Salesperson ID Sale Amount")
print("="*52)
# remove empty strings
all_data.remove('')
for data in all_data:
sales_person_id, amount = data.split()
# convert amount to float
amount = float(amount)
# if next id has appeared then print current_total of previous id
if current_id != sales_person_id and current_id != None:
print(
f'Total sales for this salesperson:${international_format(current_total)}')
current_id = None
total+=current_total
current_total = 0
if current_id == None:
current_id = sales_person_id
# print id and amount
print(f'{sales_person_id}\t${international_format(amount)}')
current_total += amount
# for last id
total+=current_total
print(
f'Total sales for this salesperson:${international_format(current_total)}')
print(f'Total of all sales: ${international_format(total)}')
Screenshot:
Output:
I need a simple python code Brewster’s Used Cars, Inc. employs several salespeople. Brewster, the owner...
2. Sales Report - PSEUDOCODE 15 PTS + PYTHON 20 PTS Brewster’s Used Cars, Inc. employs several salespeople. Brewster, the owner of the company, has provided a file that contains sales records for each salesperson for the past month. Each record in the file contains the following two fields: ● The salesperson’s ID number, as an integer ● The amount of a sale, as a real number Programming Exercises Programming Exercises 427 The records are already sorted by salesperson ID....