Starting Out with Python (4th Edition)
4th Edition
ISBN: 9780134444321
Author: Tony Gaddis
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 6.2, Problem 12CP
Write a short
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Write a short program that uses a for loop to write the numbers 1 through 10 to a file.
Write a program using a for loop that creates a file and adds the integers 1 through 10 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 11 through 20
Delete the following numbers from the file 16, 17, 18 (using a temp.txt file)
Change the number 10 to 50
You may NOT use a LIST to solve this problem
program - python
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)
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.
Chapter 6 Solutions
Starting Out with Python (4th Edition)
Ch. 6.1 - What is an output file?Ch. 6.1 - What is an input file?Ch. 6.1 - What three steps must be taken by a program when...Ch. 6.1 - Prob. 4CPCh. 6.1 - Prob. 5CPCh. 6.1 - When writing a program that performs an operation...Ch. 6.1 - If a file already exists, what happens to it if...Ch. 6.1 - What is the purpose of opening a file?Ch. 6.1 - What is the purpose of closing a file?Ch. 6.1 - Prob. 10CP
Ch. 6.1 - In what mode do you open a file if you want to...Ch. 6.2 - Write a short program that uses a for loop to...Ch. 6.2 - Prob. 13CPCh. 6.2 - Assume the file data.txt exists and contains...Ch. 6.2 - Prob. 15CPCh. 6.3 - Prob. 16CPCh. 6.3 - Prob. 17CPCh. 6.3 - Prob. 18CPCh. 6.4 - Prob. 19CPCh. 6.4 - Prob. 20CPCh. 6.4 - What type of exception does a program raise when...Ch. 6.4 - Prob. 22CPCh. 6 - A file that data is written to is known as...Ch. 6 - A file that data is written to is known as...Ch. 6 - Before a file can be used by a program, it must be...Ch. 6 - When a program is finished using a file, it should...Ch. 6 - The contents of this type of file can be viewed in...Ch. 6 - This type of file contains data that has not been...Ch. 6 - When working with this type of file, you access...Ch. 6 - When working with this type of file, you can jump...Ch. 6 - This is a small holding section" in memory that...Ch. 6 - This marks the location of the next item that will...Ch. 6 - When a file is opened in this mode, data will be...Ch. 6 - This is a single piece of data within a record. a....Ch. 6 - Prob. 13MCCh. 6 - Prob. 14MCCh. 6 - Prob. 15MCCh. 6 - When working with a sequential access file, you...Ch. 6 - When you open a file that file already exists on...Ch. 6 - The process of opening a file is only necessary...Ch. 6 - Prob. 4TFCh. 6 - When a file that already exists is opened in...Ch. 6 - Prob. 6TFCh. 6 - You can have more than one except clause in a...Ch. 6 - Prob. 8TFCh. 6 - Prob. 9TFCh. 6 - Describe the three steps that must be taken when a...Ch. 6 - Why should a program close a file when it's...Ch. 6 - What is a read position? where is the read...Ch. 6 - If an existing file is opened in append mode, What...Ch. 6 - If a file does not exist and a program attempts to...Ch. 6 - Write a program that opens an output file with the...Ch. 6 - Write a program that opens the my_name.txt file...Ch. 6 - Write code that does the following: opens an...Ch. 6 - Prob. 4AWCh. 6 - Modify the code that you wrote in problem 4 so it...Ch. 6 - Write code that opens an output file with the...Ch. 6 - A file exists on the disk named students. txt. The...Ch. 6 - A file exists on the disk named students txt. The...Ch. 6 - Prob. 9AWCh. 6 - Prob. 10AWCh. 6 - File Display Assume a file containing a series of...Ch. 6 - File Head Display Write a program that asks the...Ch. 6 - Line Numbers Write a program that asks the user...Ch. 6 - Item Counter Assume a file containing a series of...Ch. 6 - Sum of Numbers Assume a file containing a series...Ch. 6 - Average of Numbers Assume a file containing a...Ch. 6 - Random Number File Writer Write a program that...Ch. 6 - Random Number File Reader This exercise assumes...Ch. 6 - Prob. 9PECh. 6 - Golf Scores The Springfork Amateur Golf Club has a...Ch. 6 - Personal Web Page Generator Write a program that...Ch. 6 - Average Steps Taken A Personal Fitness Tracker is...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
Describe a method that can be used to gather a piece of data such as the users age.
Web Development and Design Foundations with HTML5 (8th Edition)
This optional Google account security feature sends you a message with a code that you must enter, in addition ...
SURVEY OF OPERATING SYSTEMS
What is the disadvantage of having too many features in a language?
Concepts Of Programming Languages
Answer question 3.33, but do not consider any pet having the breed of Unknown.
Database Concepts (8th Edition)
Present Value Suppose you want to deposit a certain amount of money into a savings account and then leave it al...
Starting Out with C++ from Control Structures to Objects (9th Edition)
Comprehension Check 8-12
An object is completely submerged in a liquid with a specific gravity of 0.75 at a dep...
Thinking Like an Engineer: An Active Learning Approach (4th Edition)
Knowledge Booster
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
- This program will use an interval [a, b] where a=1 and b=10. Write a program that will compute the values of the equation: y = (x-4)*(x-4) + 3 for integer x on the interval [a, b] and write them to a file named loop.cpp. You should write the function using (a) for loop, and (b) while looparrow_forwardWrite code that does the following: opens an output file with the filename number_list.txt, uses a loop to write the numbers 1 through 100 to the file, and then closes the file.arrow_forwardWrite a program using a for loop that creates a file and adds odd numbers that are in the integers 1 through 20 to the file. Name the file as 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 11 to 50 (using a temp.txt file)arrow_forward
- In C++arrow_forwardSummary In this lab, you write a while loop that uses a sentinel value to control a loop in a Python program. You also write the statements that make up the body of the loop. Each theater patron enters a value from 0 to 4 indicating the number of stars that the patron awards to the Guide’s featured movie of the week. The program executes continuously until the theater manager enters a negative number to quit. Instructions Make sure the file MovieGuide.py is selected and open. Write thewhile loop using a sentinel value to control the loop, and also write the statements that make up the body of the loop. Execute the program by clicking the Run button at the bottom of the screen. Input the following as star ratings: 0, 3, 4, 4, 1, 1, 2, -1 must be written with this code: """ MovieGuide.py This program allows each theater patron to enter a value from 0 to 4 indicating the number of stars that the patron awards to the Guide's featured movie of the week. The program executes…arrow_forwardpython Write a program that uses a text file to store the days and hours that a user worked in a week. The program should begin by prompting for the number of days worked in the week. It should continue with a loop for input of the days and hours and for writing these to the file, each on its own line. Sample Output (inputs shown in boldface)How many days did you work this week? 5Enter day of week MondayHow many hours did you work on Monday? 10Enter day of week TuesdayHow many hours did you work on Tuesday? 8Enter day of week WednesdayHow many hours did you work on Wednesday? 12Enter day of week FridayHow many hours did you work on Friday? 12Enter day of week SaturdayHow many hours did you work on Saturday? 8File was createdarrow_forward
- Please I really need help with this question it is confusing me a lot I don't understand how should I start, Also can you please attach the TEXT FILE Screenshot. PLEASE! Write a program that allows the user to navigate lines of text in a file. The program should prompt the user for a filename, read the file and input the lines of text into a list. The program then enters a loop in which it prints the number of lines in the file and prompts the user for a line number. Actual line number range from 1 to the number of lines in the file. If the input is 0, the program quits. Otherwise, the program prints the text associated with that number. You must also run the script and provide a screenshot of the output along with the textfile.arrow_forwardIn C programming. Write a loop that will write a file that looks like the following :12 2413 2614 2815 3016 3217 34arrow_forwardplease I need the best answer Write the code that opens an output file with the filename fifty.txt, uses a loop to write the numbers 1 through 50 to the file, and closes the file.arrow_forward
- Question 4: Quote Filename: quote.py Write a program that reads in an integer representing the number of sentences in the quote. For each sentence in the quote, the program should prompt for the length of the sentence and then read in that number of words from the keyboard. At the end of each sentence add a period ("") and go to the next line. After all of the words in the quote are read, then print the quote to the screen. For example: Number of sentences: 4 Enter length: 3 Roses are red. > Violets are blue. > There is no try. > Just do not or do.arrow_forwardPython programming help I need help of question 1 to read a file from persons.txt Write a program that takes a person’s details (name, age and a city), and writes to a file (persons.txt) using a loop repeatedly. You should write three person’s to the file. The program terminates on entering any key by the user, except on (Y or y) key. Sample output of the first run of the program is shown below: Enter name: JohnEnter age: 20Enter city: SydneyData saved: John 20 SydneyPress (Y or y) to add another person, or any key to exit Question 1) Write a program that read a file (persons.txt) from previous question given on the top of this question, and shows all the records/lines from the file as a nicely formatted report with a header as shown: Name Age City +---------------------+--------------------+--------------arrow_forwardim usually using python Write a program named filemaker.py that will be used to store the first name and age of some friends in a text file named friends.txt. The program must use a while loop that prompts the user to enter the first name and age of each friend. Each of these entries should be written to its own line in the text file (2 lines of data per friend). The while loop should repeat until the user presses Enter (Return on a Mac) for the name. Then, the file should be closed and a message should be displayed. See Sample Output.SAMPLE OUTPUT Enter first name of friend or Enter to quit DennyEnter age (integer) of this friend 24Enter first name of friend or Enter to quit PennyEnter age (integer) of this friend 28Enter first name of friend or Enter to quit LennyEnter age (integer) of this friend 20Enter first name of friend or Enter to quit JennyEnter age (integer) of this friend 24Enter first name of friend or Enter to quit File was createdarrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Files & File Systems: Crash Course Computer Science #20; Author: CrashCourse;https://www.youtube.com/watch?v=KN8YgJnShPM;License: Standard YouTube License, CC-BY
UNIX Programming (Part - 10) The File System (Directories and Files Names); Author: ITUTEES;https://www.youtube.com/watch?v=K35faWBhzrw;License: Standard Youtube License