What is the values in x after running the following code segment? my file = open ('test.txt') x = 0 for line in my file: line line.strip ( ) = x + len (line) my_file.close () test.txt Omer 1 Matt 2
Q: Write a program that reads in words from a file and prompts the user for another word. Print the…
A: // word, to be searched in a file string word; Then, find out the longest word from the…
Q: 5. Write a program that checks whether a sequence of HTML tags is properly nested. For each opening…
A: using linked list Linked list is a linear data structure in which elements are not stored at…
Q: Write a program that reads the-zen-of-python.txt and writes each line to UpdatedZen.txt, a new text…
A: import sys# files infile = Noneoutfile = Nonetry: # try to open infile =…
Q: Does the class FileOutputStream have a constructor that accepts a filename as an argument?
A: Does the class FileOutputStream have a constructor that accepts a filename as an argument?
Q: Given the following block of code: file="/values.dat" while IFS=, read -r value1 value2 value3; do…
A: IFS is used when you're reading several variables with read: So in this peace of code, we are…
Q: Write a program in python with no imports named filemaker.py that will be used to store the first…
A: Note: As per our honour code, we’ll answer the first question since the exact one wasn’t specified.…
Q: Write a program that reads every line in a text file, removes the first wordfrom each line, and then…
A: Given: Write a program that reads every line in a text file, removes the first wordfrom each line,…
Q: 3. Write the final content of the test.txt file. #include void main(){ id: 1058 FILE *file; int i,…
A: - We need to show what will be in the file finally after we execute the code.
Q: Why don't we just retain this information in a separate file instead of including it directly into…
A: Introduction: Why not keep this information in the code itself instead of in a separate file? The…
Q: This is for devc++ version 5.11) Create a text file with following data to test your code. Read the…
A: Actually, array is a collection of elements.
Q: The shortcut of the file have the same size as the original file but we can add it on the Desktop in…
A: Shortcut file is the only link file Which contains information of original file.
Q: Write a program that prompts the user for an input file name, reads all words from the input file,…
A: ALGORITHM:- 1. Take input for file name from user. 2. Read the data from it. 3. Write that data into…
Q: write a batch file for windows to sort a table by column from a text file. The user will be able…
A: The following is the code to sort the file. echo "Sort the file by column: " echo "choose from…
Q: Write a program that reads the contents of the file1.txt then write the even numbers to…
A: Solution:- In the below-written code, we will open the file "file1.txt" in read mode as f1 (because…
Q: Which try-with-resources statement correctly declares resources that open file in txt for reading…
A: Let us see the answer below.
Q: Write a test client which takes a file path as an argument and reads each line one by one. The file…
A: A DNA string is a Watson-Crick palindrome when the complement of its reverse is equal to itself.…
Q: Write a program that removes all the occurrences of a specified string from a text file. For…
A: This program is done with java file operations. So initially reading the file arguments from the…
Q: s there anything wrong with the following Spark code?
A: As mentioned in the question, the size of the file is much larger. The size of file.txt is 100 GB.…
Q: We have a text data file with 9 records. Each record has a name, a midterm score, and a final exam…
A: Create Your .CSV file in The same Folder as your Code . Avoid Indentation Error. Hope This will Help…
Q: try: f-open("demofile.txt", "r" ) f.write("Lorum Ipsum") except: print("Something went wrong when…
A: Here the given file demofile.txt cannot be opened and is not writable. It is read only file. Hence…
Q: Write an address book program that stores your contacts' names and their email addresses. The names…
A: Answer: I have done in python programming language. and also i have attached code as well as code…
Q: What are the contents of the file out.txt after the execution of the following code? advice - 'earn…
A: In this program after splitting by \n we have the content earn awesome kicks driving on route one
Q: . What is the purpose of the line marked as "Line1" in the following code? E = {} fh =…
A: #line1 marked because readline reads only first line of the file and that is indication of comment…
Q: Write a program to write a pattern into a new file (result.txt) as shown below (6 rows of "*" ), the…
A: The solution to the given problem is below. **Note: As programing language is not mentioned in the…
Q: Create a file called toJSON that reads a .txt file from the command line. This file should always…
A: Code :- var fs=require('fs'); //read command line args const args = process.argv.slice(2); //if…
Q: Write a Python program that reads each line of an input file called data.txt that consists of a…
A: Algorithm: Start Read the content of data.txt file and store the content in data Open sorted.txt…
Q: Write a program in python with no imports named filemaker.py that will be used to store the first…
A: Create a file named filemaker.pyPrompt user for name of a friend and his age repeatedly until user…
Q: Computer Science For each of the code snippet given below, identify the error and then write code…
A: Errors in the snippet: * in the code they haven't specified the buff_size * they haven't used the…
Q: Write a program that replaces each line of a file with its reverse. For example, if you run java…
A: The required java program is provided below in the next step.
Q: Write a program that prompts the user for an input file name, reads all words from the input file,…
A: Create a objects of input and output file. Then read input file name Then open input file using…
Q: Write a program that finds all occurrences of a word in all the filesunder a directory, recursively.…
A: Program: //include the required header files import java.io.*; import java.util.Scanner;…
Q: Write a program that creates the file "LetterGrades.txt" filled with 1000 randomly generated letter…
A: import random def main(): #create variable for file name fileName = 'LetterGrades.txt'…
Q: write a batch file which sort a table by column if we take that table for exempel
A: echo "Sort the file by column: " echo "choose from below to sort" echo "i | n | w | l | c | a" read…
Q: Write a Python code that picks a specific item from a text file that has colon(:) as a delimiter…
A: Read file line by line Then split it : and check number of words in split data If there is more than…
Q: Write a program that meets the followingrequirements:■■ Get an audio file from the class directory…
A: Program approach Import required classes from JavaFX packages. Create a class PlayAudio that…
Q: Suppose I have a data frame New1 loaded with the data from some file. If I want to delete all the…
A: dropna() in pandas is used to drop all the rows in data frame. It can also used to delete all rows…
Q: Write a program that readswords from a text file and displays all the words (duplicates allowed)…
A: PROGRAM: //Header files import java.io.*; import java.util.*; //Defining the class class Main {…
Q: Write a program that prompts the user to enter afile name and displays the occurrences of each…
A: Since programming language is not mentioned in the question, we will answer this question in the…
Q: write a batch file which sort a table by column where the user can choose sort by any column.
A: data.txt ID Name Weight Long Class Age012 Eric 56 156 7 13045…
Q: Write a program that will count the number of characters, words, and lines in a file. Words are…
A: Write a program that will count the number of characters, words, and lines in a file. Words are…
Q: Write a program in a single file that: Main: Creates 10 random doubles, all between 1 and 11, Calls…
A: Create an object for a file. Declare an array to store the random numbers of type double. Take a…
Q: Give the line(s) of code required to create a scanner object that will read text from a file called…
A: There are several ways to read a file in java.We can use Scanner, FileReader, FileInputStream and…
Q: Write a program that replaces each line of a file with its reverse. For example, if you run java…
A: JAVA program that replaces each line of file with its reverse import java.util.*;import…
Q: Write a program that will countthe number of characters, words, and lines in a file. Words are…
A: import java.io.*; import java.util.*; public class Exercise12_13 { public static void…
Step by step
Solved in 4 steps with 3 images
- Design a program that reads a file called sales.txt containing the following data: Jane, 215.5,445.5,910.0 John, 825.0,250.5,675.0 Bill,0.0,999.15 Each line has a employee's name and their weekly sales totals all separated by commas. Some employees have taken vacation some weeks so no numbers are captured for those weeks. Create a function that takes a list of floats and returns the average value for those numbers. After reading the information from the file, use a for loop to calculate the sales average using your new average function for each employee and display the following output to the screen. Jane, average sales: 523.67 John, average sales: 583.50 Bill, average sales: 499.56In Python Write a program that consists of (at least) two function: A function that creates and saves data in a file. The saved data represents exam grades. In the function, you will create n random numbers in the range [0,100], where n is the number of students. The function can be called as follows: createFile(filename, n) Main function, in which the user inputs the file name and the number of students, then the main calls function createFile. The main should perform validation for n (should be > 0), and the filename (should end with .txt). I will explain how to validate strings in the coming lecture. Hint: a good developer will write four functions to solve the problem.please code in pythonredact_file: This function takes a string filename. It writes a new file that has the same contentsas the argument, except that all of the phone numbers are redacted. Assume that the filename has onlyone period in it. The new filename is the same as the original with '_redacted' added before theperiod. For instance, if the input filename were 'myfile.txt', the output filename would be'myfile_redacted.txt'. Make sure you close your output file.The first hard task in this function is to make the output filename from the input filename that waspassed in. You can break it into two pieces by splitting on the dot or by using the index method andslicing. Then put it back together again using string concatenation.We are also working with files in this one. To open a file with a filename stored in the variable fname,in read mode use the open function as such: fp = open(fname). You will need to open the outputfile in write mode: open(fname, 'w'). Then you can traverse the…
- Write a function that reads a single line of numbers from a file named "question1.txt", and returns the average of the numbers read. For example, if the file is as follows: ----- question1.txt ----- 1 3 5 -2 4 0 6 -2 -3 ------------------------- then the function must return 12/9 = 1.33333 """ def file_average(): return # Remove this line to answer this questionWrite a program called p1.py that contains a function called filereader() that takes a number n (int) and a filename (string) as input. The function should read and store every nth line of the file in a list and return it.Test your function inside the main function (don’t forget the main guard).Sample output with “samplefile_t8.txt” file. It contains the following lines of text.kangaroo, 5capybara, 7wombat, 2koala, 3wallaby, 4quokka, 5platypus, 9dingo, 2kookaburra, 1>>> filereader(“samplefile_t8.txt”, 3) returns[“wombat, 2”, “quokka, 5”, “kookaburra, 1”]Write a function that reads a single line of numbers from a file named "question1.txt", and returns the average of the numbers read. For example, if the file is as follows: question1.txt 1 3 5 -2 4 0 6 -2 -3 then the function must return 12/9 = 1.33333 def file_average()= in python
- Create a program that reads three lines from a text file. Each line should be read one at a time. For each word on a line, the user should be asked to specify how many syllables are in that word. The program should then inform the user if the file contains a valid Hiku using the function below: def isHiku (firstLine, secondLine, thirdLine):if (firstLine == 5 and secondLine == 7 and thirdLine == 5): return True return False print("The file contains a Hiku:", isHiku(5,7,5))Note: You must replace the values in the function with the numbers counted by your program.Write a function that reads a single line of numbers from a file named "question1.txt", and returns the average of the numbers read. For example, if the file is as follows: ----- question1.txt -----1 3 5 -2 4 0 6 -2 -3------------------------- then the function must return 12/9 = 1.33333please code in python count_word: This function takes a filename and a keyword. Return the number of times the keywordoccurs in the file. Initialize a variable to keep track of the number of times the keyword appears.Traverse the file by line. Use the count method on each line to find the number of times the keywordappears in it and add that amount to the variable
- The python function first_words takes one parameter, fname, the name of a text file, and returns a list containing the first word from each line of the file. For example, if the file contents are: apples are red bananas are yellow limes are green then the list ["apples", "bananas", "limes"] should be returned.NOTE: You may assume the file will contain no blank lines.BIG HINT: If line is a string representing a line of text (inside of a for loop!), then L = line.split() creates a list of the words in the line.Write a function called countWord(). It takes 2 parameters: The name of a text file(e.g. gettysburg.txt) and a word to be searched within that file. Your code should returnthe number of times the given word appears in the file.>>> countWord('gettysburg.txt', 'people')3scores.txt : Jan,86 Drew,92 Blake,85 Alex,81 Taylor,88 Jordan ,72Cam,89 The file scores.txt (attached) contains a list of names and test scores. Create a program that reads each line of the file and determines the highest score and who obtained it. This is an exercise in strings. You are required to use at least one string method to determine the names and the scores. Your output should resemble the following: Highest Score: 100Achieved by: Jay Note; i could not send an attachment of the actual file but i have copied its contents.