Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Recommended Textbook for

Fundamentals Of Database Systems

Authors: Ramez Elmasri, Sham Navathe

4th Edition

0321122267, 978-0321122261

More Books

Students also viewed these Databases questions

Question

What is topology? Explain with examples

Answered: 1 week ago

Question

What is linear transformation? Define with example

Answered: 1 week ago