Question: debugging python read sales.py def main(): # Open the sales.txt file for reading. sales_file = open('sales.txt', 'r') # From program 6-12 # Initialize an accumulator

debugging python

read sales.py

def main():

# Open the sales.txt file for reading.

sales_file = open('sales.txt', 'r')

# From program 6-12

# Initialize an accumulator to 0.0

total = 0.0

# From program 6-12

# Initialize a variable to keep count of the sales.

count = 0

#From program 6-12

print('Here are the sales for each day entered')

# Read all the lines from the file.

# Get the values from the file and total them.

for line in sales_file

# Convert a line to a float.

amount = float(line)

# Add 1 to the count variable.

count += 1

# Display the sales.

print('Day #', count, ': ', format(amount, '.2f'), sep='')

# Add the time to total.

total += count

# Close the file

sales_file.close()

#From program 6-12

# Display the total of the running times.

print('The total amount in sales is', format(amount, '.2f'))

# Call the main function

main()

writesales.py

# write_sales.py

# Chapter 6.2

def main():

# Get the number of days

num_days = int(input('For how many days do ' + \

'you have sales? ')

# Open a new file named sales.txt

sales_file = open('sales.txt', 'w')

# Get the ammount of sales for each day and write

# it to the file

for count in range(1, numd_ays + 1):

# Get the sales for a day.

sales = float(input('Enter the sales for day #' + \

str(count) + ': "))

# Write the sales amount to the file

sales_file.write(str(sales) + ' ')

# Close the file.

sales_file.close()

print('Data written to sales.txt.')

# Call the main function

main()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!