Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Question
Write a python script that opens a text file names.txt in "reading" mode, uses a for loop to scan the file, read each line and print it.
screenshot of text file included
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 3 steps with 1 images
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
- PYTHON: I need to get the avg statement out of the loop so that the output prints correctly. Any suggestions. Write a program that reads the student information from a tab separated values (tsv) file. The program then creates a text file that records the course grades of the students. Each row of the tsv file contains the Last Name, First Name, Midterm1 score, Midterm2 score, and the Final score of a student. A sample of the student information is provided in StudentInfo.tsv. Assume the number of students is at least 1 and at most 20. The program performs the following tasks: Read the file name of the tsv file from the user. Open the tsv file and read the student information. Compute the average exam score of each student. Assign a letter grade to each student based on the average exam score in the following scale: A: 90 =< x B: 80 =< x < 90 C: 70 =< x < 80 D: 60 =< x < 70 F: x < 60 Compute the average of each exam. Output the last names, first names, exam…arrow_forwardWrite program that reads a list of names from a data file and displays the names to the console. The program should prompt the user to enter a filename. Create such a file and check your code. Solve with python. Example of code format: #Prompt the user for file name file_name = input("Enter file name : ") #Open file with open(file_name,"r") as file: #Read file content f = file.readline() #split the contents into numbers numbers = f.split(' ') test_list = [int(i) for i in numbers] res = 1 #Find the product for i in test_list: res*=i #Print result print("Product of numbers in the list :",res)arrow_forwardQ1: Write a python code to read data from a file "file1.txt" and then write the data to another "file "file2.txt 4:30arrow_forward
- What does the following python code do? f = open("sample.txt", "w") Choose all that apply. Select 2 correct answer(s) a. writes "w" to the file called sample.txt b. if the file sample.txt exists, deletes everything in it c. closes a file called sample.txt d. If the file called sample.txt exists, it writes at the bottom of the file e. opens a file called sample.txt for appending f. if the file sample.txt does not exist, it creates the file and opens it for writing g. reads the file called sample.txt starting from the top h. opens a file called sample.txt for readingarrow_forwardAll I need is the main.cpp file Programming Specifications: Task: Two files have been provided (wordcounter.h and wordcount.cpp). You must open a text file, read in each word until end of file, add each word to the WordCount library and print the report. Your program must request a filename of a text file that contains words to count. You must check to see if it is a valid file and issue an error message if not and request a new file name until a valid one is entered. You must have at least one function that either passes in a parameter and at least one function that returns a value. You can have a single routine that does both. You must declare the class object properly, use AddWord() to add the word to the catalog and use PrintSummary() to produce the output. Design Considerations: The file will contain only words (no punctuation or special characters) less than or equal to 13 letters. There will be no limit to the number of words. You must open the file and read each…arrow_forwardPython programming only NEED HELP MAKING FLOWCHART FOR PROGRAM CODE IS ALREADY CORRECT JUST NEED FLOWCHART (CODE INCLUDED): My Code: def read_and_display_random_numbers(file_path):total = 0count = 0with open(file_path, 'r') as file:for line in file:random_number = int(line.strip())total += random_numbercount += 1print(random_number)return total, countif __name__ == "__main__":try:file_path = input("Enter the file path to read random numbers from: ").strip()if not file_path:raise ValueError("File path cannot be empty.")total, count = read_and_display_random_numbers(file_path)print(f"\nTotal of the numbers: {total}")print(f"Number of random numbers read from the file: {count}")except ValueError as ve:print(f"Error: {ve}")except Exception as e:print(f"An error occurred: {e}")arrow_forward
- In c programming language, read a file given a command line argument. Then print the file out with line numbers.arrow_forwardCreate a new file (in Dev C++) and save it as lab7_XYZ.cpp (replace XYZ with your initials). In Lab 2, you created a menu for a simple calculator program. In Lab 6, you added some functionality based on the user selection. In this lab, you will add some more functionality to the program. Use loops to keep running the program until the user chooses the exit condition (9). When dividing, use a loop to validate user input, making sure the denominator (second number) is not zero. If the user enters a 0 for the second number, display an error message and keep prompting until a non-zero number is entered. 1) Add two numbers2) Subtract two numbers3) Multiply two numbers4) Divide two numbers 9) Exit program The program should: contain header comments as shown in class display a hello message before presenting the menu display the menu prompt user for selection echo the selection back to the user if the selection was invalid, display error message to user and then loop back to menu…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_forward
- Write 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_forwardWrite a program that asks the user for a file name and a string to search for. The program should search the file for every occurrence of a specified string. When the string is found, the line that contains it should be displayed. After all the occurrences have been located, the program should report the number of times the string appeared in the file.arrow_forward9b_act2. Please help me answer this in python programming.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education