Starting Out with Python (4th Edition)
4th Edition
ISBN: 9780134444321
Author: Tony Gaddis
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 6.2, Problem 15CP
Program Plan Intro
Program plan:
- • Define the “main()” function to implement a file named “data.txt”.
- ○ Open a file using “open()” method with “r” mode and assign the object to “fileobject”.
- ○ Define a “for” loop to execute a file until it reaches the end of the file without checking condition.
- ■ Print the value of “line” on the screen.
- ○ Close the file using “close()” method.
- • Call the “main()” function.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
If you want to break out of an inner loop, you can use the keyword ‘break’. But if you want to break out of a nested loop, you can use a labeled jump. Give an example of how labeled jump works.
The program needs to be modified.
Explain the main difference between a while-loop and a for-loop? When would you used one over the other?
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...
Knowledge Booster
Similar questions
- For Loop in Javaarrow_forwardYou are writing an inventory system for a library. This program will allow the user to enter a book, remove a book, and find a book. The book titles will be stored in a dictionary. Each key in the dictionary is a book’s title, and each value is the number of copies currently in stock. In a continuous loop, give the user the option to add a book, remove a book, find a book, and quit. If the user chooses to add a book, call a function named add_book. This function should ask for a book title and how many copies the user is adding. If the title is not yet in the dictionary, add a new key/value pair to the dictionary with the key being the book title and the value being the amount the user is adding. If the title is already in the dictionary, update its value to include the copies the user is adding. If the user chooses to find a book, call a function named find_book which asks the user for a book title. If the book’s title exists in the dictionary, print out how many copies of it…arrow_forwardPlease refer to the picture and also rewrite it as a for loop and do- while loop. Please show your source code for all three thank you.arrow_forward
- Coin Toss, v.2.0 Purpose. Learn how to use count-controlled loops. Requirements. Rewrite your coinTossl.cpp from exercise 6.5 as coinToss2.cpp. Modify the program to allow the user to specify (via keyboard data entry) the number of coin tosses to perform. When you run the program, and it should say the result of each coin toss (that is, "Heads" or "Tails"). Supplemental. Read about "randomizing" in www.rdb3.com/cpp/exercises/Gaming.supplemental.pdf. Algorithm. Call srand Prompt the user to enter how many coin tosses to perform Input and store the user's selection Create a counter and set it to zero Start the loop here If the counter equals the number of tosses to perform Break from the loop Get and store a randomly-generated number in the range 0 to 1 If the randomly-generated number equals 0 Output "heads" If the randomly-generated number equals 1 Output "tails" Add one to the counter Loop back from here Example. with user input in blue Enter the number of tosses to perform: 3 Heads…arrow_forward(This is for devc++ but this is suppose to be done on mindmap from Cengage. I know it a little different. If you can't use Cengage, I suggest devc++ version 5.11) THANK YOU! Instructions Write a program that uses for loops to perform the following steps: Prompt the user to input two integers: firstNum and secondNum (firstNum must be less than secondNum). Output all odd numbers between firstNum and secondNum. Output the sum of all even numbers between firstNum and secondNum. Output the numbers and their squares between 1 and 10. Separate the numbers using any amount of spaces. Output the sum of the square of the odd numbers between firstNum and secondNum. Output all uppercase letters. Seperate each letter with a space PLEASE LOOK AT SCREENSHOT, that is how the letters have to bearrow_forwardWe learn about several types of loops. Describe specifically when it is appropriate to use: a for loop a while loop a do-while looparrow_forward
- How is the looping action of a basic loop stopped? a, It's stopped when the condition in the LOOP statement is FALSE. Answers: b. This type of loop has a predetermined number of loops to complete. c. The condition in an EXIT WHEN statement is FALSE. d. The condition in an EXIT WHEN statement is TRUE.arrow_forwardin C++arrow_forwardThis didn't answer the question at all. It's suppose to be a loop for invalid until they get it correct. Yours does not looparrow_forward
- Write a program that uses a “for” loop to count from 0-10 and show the numberson the screen. In the same file, re-write this program without using a “for” loop.arrow_forwardWhat is the effect of writing a break * ?statement inside a loop It cancels remaining iterations. It skips a particular iteration. The program terminates immediately. Loop counter is reset. All of the mentioned Oarrow_forwardWrite a Python loop that will start at 100 and count backwards by 2's (98, 96...) to 54. HOWEVER, I also want it to skip every third printout: 98, 96, , 92, 90, ,86.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,