EBK STARTING OUT WITH PYTHON
3rd Edition
ISBN: 9780133743661
Author: GADDIS
Publisher: PEARSON CUSTOM PUB.(CONSIGNMENT)
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
The program needs to be modified.
For Loop in Java
You 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…
Chapter 6 Solutions
EBK STARTING OUT WITH PYTHON
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 - 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...
Knowledge Booster
Similar questions
- Write 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_forwardA. LEGv8: 1. Go to the 3rd emulator in Section 2.4. Make the following change to the code there: ADD X0, XZR, XZR Loop: SUBS X3, X0, X1 B.GE Exit ADDI X0, X0, #1 B Loop Exit: We can now see what the answer is to X0-X1. What is it? ANSWER: What is in X3 just before the simulation exits?arrow_forwardconsider this data sequence: "3 11 5 5 5 2 4 6 6 7 3 -8". Any value that is the same as the immediately preceding value is considered a consecutive duplicate. Write some code that use a loop to read such a sequence of non-negative integers, terminated by a negative number. When the code finishes executing, the number of consecutive duplicates encountered is printed. using Pythonarrow_forward
- Using a Counter-Controlled whileLoop Summary In this lab, you use a counter-controlled while loop in a Java program provided for you. When completed, the program should print the numbers 0 through 10, along with their values multiplied by 2 and by 10. The data file contains the necessary variable declarations and some output statements. Instructions Ensure the file named Multiply.java is open. Write a counter-controlled while loop that uses the loop control variable to take on the values 0 through 10. Remember to initialize the loop control variable before the program enters the loop. In the body of the loop, multiply the value of the loop control variable by 2 and by 10. Remember to change the value of the loop control variable in the body of the loop. Execute the program by clicking Run. Record the output of this program.arrow_forwardYou are a cyber investigator, your task is to write a python program that can read file signatures from a file and save them into a list. Each file signature is an element of your list. Then, try to find out if there is a JPG file in there. If there is a JPG file, print out a True on screen. (File Signature for JPG file is: FF D8 FF DB) The input file is: FSCS360_Midterm_Exam_Part2.txtarrow_forwardWrite a program that uses a while loop to enable the user to enter any number of positive integers. The loop should end when a sentinel value of 0 (zero) is entered. The program should then report the sum of the even integers and the sum of the odd integers. This must be written in Python. I have most of it figured out, I just don't know how to add an accumulator for the odd and even numbers. I have attached what I have so far below. Thank you! def main():TOTAL = 0print('This program calculates all odd and even positive numbers entered')num = int(input('Enter a positive number or 0 to quit: '))while num != 0:if num % 2 == 0:print(f'This {num} is even')else:print(f'This {num} is odd')num = int(input('Enter a positive number or 0 to quit: '))total_even = num % 2 == 0total_odd = num % 2 != 0total_even_num = total_even + numtotal_odd_num = total_odd + numprint(f'Your total of even number is {total_even_num}')print(f'Your total of odd numbers is {total_odd_num}') main ()arrow_forward
- Write a for loop that prints out the integers 7 through 40, each on a new line using range (). Use while loops to print the multiplication tables of 2,3 and 4. The table must include the first 10 multiplications. (must be separate loops for each one)arrow_forwardSubject: Assembly Language Q: Write a program that displays a string in all possible combinations of foreground and background colors (16 x 16 =256). The colors are numbered from 0 to 15, so you can use a nested loop to generate all possible combinations. Also use a delay of 1s in each foreground color change.arrow_forwardIs there a way for a programmer to recognize an infinite loop and break out of it?arrow_forward
- write a different program that lets you work with the data concerning each tool, enables you to list all your tools, lets you delete a record for a tool that you no longer have and lets you update any information in the file. The tool identification number should be the record number. Use the following information for your program to work with.arrow_forwardHow to write on a file more than one data at a time using loops in java?arrow_forwardCreate a program that will compute for n! (Factorial) which is the product of all numbers from 1 to n. Implement using while loop or do while loop.NOTE: Starting this activity, you have to apply error trapping. That is, if the input is not a number, your program should prompt the user displaying “Invalid input! Try again.” and should continually ask the user for a correct input before proceeding to the next operation.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 LearningC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,
- Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage