Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

FIX MY CODE! NOT LINED UP CORRECTLY _ THANK YOU IN ADVANCE # Function to initialize a 2 D array with zeros def initialize _

FIX MY CODE! NOT LINED UP CORRECTLY_ THANK YOU IN ADVANCE
# Function to initialize a 2D array with zeros
def initialize_2d_array(rows, cols):
return [[0]* cols for _ in range(rows)]
# Function to read and process the sales data
def process_sales_data(file_path):
# Initialize sales data arrays
sales_locations =["Houston", "Dallas Fortworth", "Austin", "San Antonio", "Corpus Christi"]
auto_models =["A4 allroad", "A5 Coupe", "S5 Coupe", "RS 3","Q5 Sedan", "Q5 Sportback",
"SQ8 e-tron", "e-tron GT","S6 Sedan", "FF Heritage"]
unit_prices =[55600.00,62700.00,58250.00,59900.00,44900.00,51300.00,89800.00,106500.00,46400.00,86300.00]
# Initialize 2D array for sales
sales_array = initialize_2d_array(len(sales_locations), len(auto_models))
# Read and process the sales data from the file
with open(file_path, 'r') as file:
for line in file:
# Extract location and model codes
location_code = int(line[:2])
model_code = int(line[2:])
# Update the sales array
sales_array[location_code][model_code]+=1
# Display the report
print_report(sales_array, sales_locations, auto_models, unit_prices)
# Function to print the sales report
def print_report(sales_array, sales_locations, auto_models, unit_prices):
# Print the report header
print("*********************************************************************************************************************************************************************************************")
print(" Europian Auto Traders")
print(" Sales By Location")
print(f" Report Date: 11/25/202308:07:09")
print(" Name: Stephen Washington")
print("*********************************************************************************************************************************************************************************************")
# Print the Auto Models header
print(" Auto Models")
print("Location Name ", end='')
for model in auto_models:
print(f'{model:15}', end='')
print()
# Print the sales data
for i, location in enumerate(sales_locations):
print(f'{location:15}', end='')
for j, model in enumerate(auto_models):
print(f'{sales_array[i][j]:15}', end='')
print()
# Print the separator
print('-'*(20+15* len(auto_models)))
# Print the Totals header
print("", end='')
for j in range(len(auto_models)):
print(f'{sum(row[j] for row in sales_array):15}', end='')
print()
# Print the Unit Price header
print("Unit Price ", end='')
for price in unit_prices:
print(f'{price:.2f}', end='')
print()
# Print the separator
print('-'*(20+15* len(auto_models)))
# Print the Totals Earned header
print("Totals Earned", end='')
for j in range(len(auto_models)):
total_earned = sum(sales_array[i][j]* unit_prices[j] for i in range(len(sales_locations)))
print(f'{total_earned:.2f}', end='')
print()
# Print the final separator
print('*'*(20+15* len(auto_models)))
# Call the function with the file path
process_sales_data("autoSales.dat")
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

What is meant by planning or define planning?

Answered: 1 week ago

Question

Define span of management or define span of control ?

Answered: 1 week ago

Question

What is meant by formal organisation ?

Answered: 1 week ago

Question

What is meant by staff authority ?

Answered: 1 week ago