Write a program using a for loop that creates a file and adds even numbers the integers 1 through 20 loop to the file. Name the file numbers. txt. Then perform the following on the file: Read all of the numbers stored in the file and calculate their total. Display all the numbers in the file and the calculated total Using a for loop add the following numbers to the file 21 through 30 Delete the following numbers from the file 24, 25, 26   (using a temp.txt file) Change the number 10 to 50 (using a temp.txt file)

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter8: I/o Streams And Data Files
Section: Chapter Questions
Problem 9PP: (Inventory) Create an ASCII file with the following data, or use the shipped.dat file available on...
icon
Related questions
Question

program - python

  1. Write a program using a for loop that creates a file and adds even numbers the integers 1 through 20 loop to the file. Name the file numbers. txt. Then perform the following on the file:
  2. Read all of the numbers stored in the file and calculate their total.
  3. Display all the numbers in the file and the calculated total
  4. Using a for loop add the following numbers to the file 21 through 30
  5. Delete the following numbers from the file 24, 25, 26   (using a temp.txt file)
  6. Change the number 10 to 50 (using a temp.txt file)

 

Hint: if you want to use !

Use module os that is part of Python to manipulate files.:   import os.  You can use functions that come with “os” module.  Functions remove and rename can be used as explained below.

 

  • rename(old_name,new_name):This function renames the old_name to new_name).
  • remove(filename)method in Python is used to remove or delete a file.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
File Input and Output Operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr