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
Q: Write a function called max_age(inFile, outFile, breed), that takes three strings as input…
A: 1. create function max_age with paramter infile outfile and breed 2. try to open the input file and…
Q: Create a program that reads three lines from a text file. Each line should be read one at a time.…
A: Please upvote/Like me. please. I am providing you the correct answer below. Please. Please.
Q: Input In each test case, we will call your decrypt function with an open file that contains…
A: Encryption: It is the process of converting the given value to another value with key. It is mainly…
Q: P1. Write a Python function called reduceWhitespace that is given a line read from a text file and…
A: the- program code in python is given below:
Q: You will write a program that will calculate the area of a square based on a randomly generated…
A: I give the code along with output and code screenshot in Python
Q: Each line of a hockey file contains a four-digit year, a team name, and a two-digit number of wins.…
A: The text for the code is given below: f = open('hockey.txt')lines = f.readlines()f.close() def…
Q: a text file named FIRST.TXT contains some text written into it, write a function named copyupper(),…
A: 1. Open "FIRST.TXT" and "SECOND.TXT" files in a separate file pointer(say fin and fout ). 2. Read…
Q: write a program that computes and prints the average of the numbers in a text file. you should make…
A: in step 2, I have provided TXT FILE SCREENSHOT--- in step 3, I have provided PYTHON CODE---…
Q: Write a function file_copy that takes two string parameters (in_file and out_file) and copies the…
A: Python code :: #!usr/bin/env python def file_copy(infile, outfile): in_f = open(infile,'r') #…
Q: Write a function called max_age(inFile, outFile, breed), that takes three strings as input…
A: Since no programming language is mentioned, I am using python. Algorithm: Start Read input file…
Q: Write a function find_decrypted_words() that takes a file name as parameter, reads that text file…
A: Given:
Q: Write a program that includes a function that will find how many times an animal has been sighted.…
A:
Q: Write a program that creates a function to read multiple DNA sequences from the user and writes them…
A: Code: # Python program to convert# altered DNA to protein inputfile ="DNA_sequence_original.txt" f…
Q: You have to create a file having name Math.cpp and implement functions of the following prototypes…
A: Math.cpp #include<iostream> using namespace std; void sum(int a, int b) { cout<<"Sum…
Q: Python: Character Histogram
A: Summary: In this question, we have been one program and we have to write the code in python. In…
Q: Write code for the following: Write Python code that uses a loop to prompt the user for five…
A: Write Python code that uses a loop to prompt the user for five floating point numbers and reports…
Q: Write a complete python program with a main function that reads from a file called numbers.txt and…
A: The main objective of the python program,main.py is to read a file that contains the two numbers on…
Q: Write a program that reads a text and outputs the letters, together with their counts, as explained…
A: The program should have the following functions: Function main – calls all the functions. Function…
Q: At any given time, there can be a different set of animals in the shelter. Therefore, you do NOT…
A: PROGRAM CODE: #include <iostream>#include <fstream>#include <string>#include…
Q: Write a Python program that chooses the best 5 quiz scores from a file with student ID and scores.…
A: In this program we need to first open the file and then extract the student id and list of scores.…
Q: Write a program that includes a function that alculates the equation F= x" sin x. Write the alues n,…
A: Since no programming language is mentioned, I am using python. Algorithm: Start Initialize a list…
Q: Write a program that reads a text and outputs the letters, together with their counts, as explained…
A: Program code: #include <iostream> #include <fstream> using namespace std; // Create a…
Q: Write a function find_lowers() that takes a file name as a parameter, reads that text file, and…
A: Since no programming language is mentioned, I am using python. Algorithm: Start Read file name…
Q: Write a program whose main function is merely a collection of variable declarations and function…
A: #include <iostream> #include <fstream> using namespace std; // Create a struct…
Q: Write a function named framestr that takes as input a string s, and PRINTS on the screen a framed…
A: len(s) find length of string s '-' * n '-' copy it n times if n=5 '-'*n = '-'*5 = '-----'
Q: Please answer it in Python Below are the first 4 lines of such a file whose number of lines is not…
A: Hey there, I am writing the required solution of the above stated question.Please do find the…
Q: Create an anonymous function f which accepts a vector valued numeric input (from x=0 to x=5 with 0.5…
A: NOTE: In the image, it is shown that the compiler is MATLAB. Therefore answering in MATLAB language.…
Q: The file text.txt contains a sentence text written in all small letters and does not have any…
A: import java.io.*; import java.util.*; // We have a class named Main public class Main { // We…
Q: Write a program that reads a text and outputs the letters, together with their counts, as explained…
A: Program code: #include <iostream> #include <fstream> using namespace std; // Create a…
Q: Python programming language Write a program that asks the user for a number. Write the number…
A: Given: Python programming language Write a program that asks the user for a number. Write the…
Q: Write a program whose main function is merely a collection of variable declarations and function…
A: Since the Programming language is not mentioned in the question, we will answer this question in C++…
Q: Write a program that reads a text and outputs the letters, together with their counts, as explained…
A: A C++ program for the given criteria is as follows, #include <iostream> #include…
Q: Write a program which has a class named FileHandler to read StudentName, MarksObtained from the…
A: Note: As you have not specified any language, I have written a program in JAVA.
Q: Write a function void saveByDept(char *fileName, char *deptName , student allStudents[], int size)…
A: The following is the solution In saveByDept method File is open in write mode and fprintf has been…
Q: Write a function getQuestions that accepts a single parameter: filename, which is the name of a txt…
A: Note : As you have not mentioned any language for programming but the description clearly shows that…
Q: python Write a function that reads in a text file, and counts the number of times each word occursin…
A: The program first creates a file sample.txt and stores a string in it. Then it reads the created…
Q: Write a Python program that calculates the average 5 quiz scores fr Your program must have 2…
A: Note: Both txt files and .py files should be saved in Desktop. i consider only 5 quizes but the…
Q: (a) Write a C function readNums() that takes a filename and an integer array, reads the integer…
A: // Declaring header files#include <stdio.h>#define MAX 1000 // Function to read numbersint…
Q: Write a function that takes a file name to read and then counts the number of words in the file…
A: The solution for the above given question is given below:
Q: Implement a function wordCount, which reads a text file, and returns the number of words in the…
A: since you haven't mentioned the programming language, we are answering this in c. Program code:…
Q: Write a program to sort a list of numbers of unknown length. Your program must • read in a list (of…
A: The complete code is given below.
Q: Write a function named frameStr that takes as input a string s, and PRINTS on the screen a framed…
A: PROGRAM EXPLANATION: Define a function framestr(str). This function will take a string as an input…
Q: Write a function (in a file called convert_knots.cpp) that converts knots into miles per minute. The…
A: The program is written in C++. Check the program screenshot for the correct indentation. Please…
Q: Write a python program that contains a function called filereader() that takes a number n (int) and…
A: Given: Write a python program that contains a function called filereader() that takes a number n…
Q: Write a C function named int getNumberOfWords( FILE* fp) which finds the number of lines in the…
A: /*Program to find number of lines in the file*/ #include <stdio.h>#define MAX_FILE_NAME 100…
Q: Each line of a hockey file contains a four-digit year, a team name, and a two-digit number of wins.…
A: - We need to code the team problem. - We have to use python here.
Q: Your function must find the oldest pet of a given breed (3rd input parameter) from the inFile and…
A: 1. function max age : parameter infile outfile breed a. open both file in try block b.…
Q: Write a function that reads a single line of numbers from a file named "question1.txt", and returns…
A: The problem is based on finding the average of numbers after reading the data from the file in…
Q: You are given a file consisting of students’ names in the following form: lastName, firstName,…
A: Programming language is missing in the question. So we will answer this program in C++ language. If…
Q: Write a function charHistogram(filename: str) -> None that takes the file name of a text file and…
A: It is defined as a frequency distribution shows how often each different value in a set of data…
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
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 3 images
- 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 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(5) Write a function called copy_even_lines() that takes two strings (filenames) as input parameters and copies every other line from the first file into the second. That is, counting from 0, it copies the 0th line, the 2nd line, the 4th line, etc. from the first file to the second file. You may assume that both files exist. (6) Write a python program that asks the user for two filenames and calls your function copy_even_lines() from (5) using those two filenames. If one or more files do not exist, your program must handle the exception by repeating the prompts until valid filenames are entered.
- Write a program vote.cc that allows to read from a file vote.in thelast names of the candidates in an election and the number of votes received by eachcandidate. The program should then output each candidate’s name, the number of votesreceived, and the percentage of the total votes received by the candidate. Your programshould also output the winner of the election. Your program should have at least the following functions:(a) Write a function openFile that prompts a user to enter a file name and opens it.(b) Write a function closeFile that closes an open file.(c) Write a function getData that reads from the file the candidate names and theirnumber of votes received and returns them in 2 separate arrays.(d) Write a function sumVote that takes as its parameter an array of number of votesand returns the total number of votes.(e) Write a function computePercentages that takes as its parameters an array ofnumber of votes and returns an array of percentages of votes. Your function shoulduse…Write a program that reads words from a file (filename given as a string parameter) and prints the occurance of each word(case insensitive). And print the words in alphabetical order. For example, if the file contains text Love is free free is love then the function should print free:2 is:2 love:2 def count_word(filename): # YOUR CODE HERE raise NotImplementedError()Write a function called max_age(inFile, outFile, breed) for a (python program), that takes three strings as input parameters. The function reads all the data from the inFile (1st input parameter) and writes data to the outFile (2nd input parameter) as described below. Each line in the input file represents a pet record and has the following format. name, breed, age where name and breed are strings, and age is an integer value. Your function must find the oldest pet of a given breed (3rd input parameter) from the inFile and write the following information to the outFile. breed, total records of this breed name of the oldest pet, age of the oldest pet Note that outFile must only have these two lines of information. Suppose, inFile contains the following data: shadow, longhair, 3 poshi, bangal, 5 mikus, longhair, 4 tigger, calico, 9 If you call this function with breed = "longhair", then the following must be written in the outFile: longhair, 2 mikus, 4 Your…
- Write a program that reads a text and outputs the letters, together with their counts, as explainedbelow in the function printResults. Your program should not have any global variables. Allinformation should be accessed through the parameters of the functions. Your program shouldhave the at least the following functions:• Function main – calls all the functions• Function openFile – opens the input and ouput files. This program has the file streamdeclare a refence parameter. An appropriate error message should be displayed if the filedoes not exist. The program must ask the user for the names of the input and output files.• Function countLetters – counts every of uppercase letters A – Z and lower-case lettersfrom a – z in the text file opened in the function openFile. This information should be storedin an array of structures. Both the array and file identifiers must be passed as parameters.• Function printResults – prints the number of uppercase letters for every occurrence of A–Zand…Write a program that reads a text and outputs the letters, together with their counts, as explained below in the function printResults. Your program should not have any global variables. All information should be accessed through the parameters of the functions. Your program should have the at least the following functions: • Function main – calls all the functions • Function openFile – opens the input and ouput files. This program has the file stream declare a refence parameter. An appropriate error message should be displayed if the file does not exist. The program must ask the user for the names of the input and output files. • Function countLetters – counts every of uppercase letters A – Z and lower-case letters from a – z in the text file opened in the function openFile. This information should be stored in an array of structures. Both the array and file identifiers must be passed as parameters. • Function printResults – prints the number of uppercase letters for every occurrence…Write a program that reads a text and outputs the letters, together with their counts, as explained below in the function printResults. Your program should not have any global variables. All information should be accessed through the parameters of the functions. Your program should have the at least the following functions: • Function main – calls all the functions • Function openFile – opens the input and ouput files. This program has the file stream declare a refence parameter. An appropriate error message should be displayed if the file does not exist. The program must ask the user for the names of the input and output files. • Function countLetters – counts every of uppercase letters A – Z and lower-case letters from a – z in the text file opened in the function openFile. This information should be stored in an array of structures. Both the array and file identifiers must be passed as parameters. • Function printResults – prints the number of uppercase letters for every occurrence…
- Write a function in python named "read_words" that declares a parameter for a filename and returns a collection of unique words in the file. Even though words.txt contains a single word per line, you should not assume that this is true of every file. For example, if the line is a sentence, you should split the line into individual words before storing each word in your collection. Handle any errors that occur by printing a detailed error message. Hint: the Python set works like Java's HashSet.Write a program that reads a text and outputs the letters, together with their counts, as explainedbelow in the function printResults. Your program should not have any global variables. Allinformation should be accessed through the parameters of the functions. Your program should:have the at least the following functions:• Function main – calls all the functions• Function openFile – opens the input and ouput files. This program has the file streamdeclare a refence parameter. An appropriate error message should be displayed if the filedoes not exist. The program must ask the user for the names of the input and output files.• Function countLetters – counts every of uppercase letters A – Z and lower-case lettersfrom a – z in the text file opened in the function openFile. This information should be storedin an array of structures. Both the array and file identifiers must be passed as parameters.• Function printResults – prints the number of uppercase letters for every occurrence of A–Zand…Write a program whose main function is merely a collection of variable declarations and function calls. This program reads a text and outputs the letters, together with their counts, as explained below in the function printResult. (There can be no global variables! All information must be passed in and out of the functions. Use a structure to store the information.) Your program must consist of at least the following functions: Function openFile: Opens the input and output files. You must pass the file streams as parameters (by reference, of course). If the file does not exist, the program should print an appropriate message ("The input file does not exist.") and exit. The program must ask the user for the names of the input and output files. Function count: Counts every occurrence of capital letters A-Z and small letters a-z in the text file opened in the function openFile. This information must go into an array of structures. The array must be passed as a parameter, and the file…