Concept explainers
Write a
(n1 – a)2, (n2 – a)2, (n3 – a)2 and so forth
The number a is the average of the numbers n1 n2, n3, and so forth. If this is being done as a class assignment, obtain the file name from your instructor. (Hint: Write your program so that it first reads the entire file and computes the average of all the numbers, and then doses the file, then reopens the file and computes the standard deviation.)
Want to see the full answer?
Check out a sample textbook solutionChapter 6 Solutions
Problem Solving with C++ (10th Edition)
Additional Engineering Textbook Solutions
Concepts Of Programming Languages
Starting Out with C++ from Control Structures to Objects (9th Edition)
Starting Out with Python (4th Edition)
Modern Database Management
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Starting Out With Visual Basic (8th Edition)
- Code should be in Python. Given a text file containing the availability of food items, write a program that reads the information from the text file and outputs the available food items. The program first reads the name of the text file from the user. The program then reads the text file, stores the information into four separate lists, and outputs the available food items in the following format: name (category) -- description Assume the text file contains the category, name, description, and availability of at least one food item, separated by a tab character ('\t'). (Examples in image)arrow_forwardExercise 3: Write a program that reads from an input file “scores.txt” student test scores inthe range 0 – 100 and store these scores in a list. Your program should determine the numberof students having scores in each of the following ranges: 0-59, 60-79, 80-89, and 90-100.Display the score ranges and the number of students. (Hint: store the ranges as a list). If yourun your program with the following data:76, 89, 100, 95, 90, 100, 76, 100, 50, 67, 78, 89, 77, 89, 98Your output should be as follows:Number of students: 15 0-59 60-79 80-89 90-100 ===== ===== ===== ====== 1 5 3 6 Your program should have at least these 3 functions:1. main(): displays the ranges and the number of students in each range2. readData(): reads data from input file into a list3. splitIntoRanges(): takes a list of scores and determines the number of studentsin each score rangearrow_forwardPython please: Given the input file input1.csv write a program that first reads in the name of the input file and then reads the file using the csv.reader() method. The file contains a list of words separated by commas. Your program should output the words in a sorted list. The contents of the input1.csv are: hello,cat,man,hey,dog,boy,Hello,man,cat,woman,dog,Cat,hey,boy Example: If the input is input1.csv the output is: ['Cat', 'Hello', 'boy', 'boy', 'cat', 'cat', 'dog', 'dog', 'hello', 'hey', 'hey', 'man', 'man', 'woman'] Note: There is a newline at the end of the output.arrow_forward
- In Python I keep getting a white space error in my code Write a program that first reads in the name of an input file and then reads the file using the csv.reader() method. The file contains a list of words separated by commas. Your program should output the words and their frequencies (the number of times each word appears in the file) without any duplicates. Ex: If the input is: input1.csv and the contents of input1.csv are: hello,cat,man,hey,dog,boy,Hello,man,cat,woman,dog,Cat,hey,boy the output is: hello 1 cat 2 man 2 hey 2 dog 2 boy 2 Hello 1 woman 1 Cat 1 Note: There is a newline at the end of the output, and input1.csv is available to download. 247772.1944916.qx3zq My Code: import csv # to store wordswords= []# openfilewith open('input1.csv') as f:for row in csv.reader(f, delimiter=','):# read data, add to wordswords += row # get unique words unique_words = sorted(set(words), key=words.index) for word in unique_words : # print words followed by space then its…arrow_forwardPython languagearrow_forwardPython languagearrow_forward
- Python Write a program that first reads in the name of an input file and then reads the file using the csv.reader() method. The file contains a list of words separated by commas. Your program should output the words and their frequencies (the number of times each word appears in the file) without any duplicates. Ex: If the input is: input1.csv and the contents of input1.csv are: hello,cat,man,hey,dog,boy,Hello,man,cat,woman,dog,Cat,hey,boy the output is: hello 1 cat 2 man 2 hey 2 dog 2 boy 2 Hello 1 woman 1 Cat 1 my code is not working, this is what i have: import csv # to store wordswords= []# openfilewith open('input1.csv') as f:for row in csv.reader(f, delimiter=','):# read data, add to wordswords += row # get unique words unique_words = sorted(set(words), key=words.index) for word in unique_words : # print words followed by space then its countprint(word , words.count(word), end =" ") # formatted output at endprint("")arrow_forwardWrite a Python program that calculates the average 5 quiz scores from a file with student ID and scores. Your program must have 2 functions; the main and calculateAvg- The main function reads data from an input file, which has the format shown below. Each line in the file starts with the Student ID followed by 5 values representing the scores attained by the Student in 5 quizzes. For each Student, the calculateAvg function receives a list containing the 5 values and returns another list containing all the values in the original list plus the average score of the quizzes for each student. This information will be written in an output file as shown below. Also, you must include the class average at the end. Which includes all the students in the list. Note: You program must be general and works for any number of Students. All reading and writing must be done in the main function. Assume each student has 5 quiz scores Input text file name must be grades.txt Output text file name must be…arrow_forwardGiven the formula for converting Fahrenheit (F) to Celcius (C):C = 5/9 x (F - 32),where C is the unit of temperature in Celcius and F is the unit of temperature in Fahrenheit. Write a complete C++ program that reads in a list of data F from a text file, then calculates the values of C using the formula given. The program should use an array to store the values of F as example shown in Figure 4. 13.2929.7614.8123.7829.37.. Figure 4: Example of data F in the input file The program then prints a summary output onto the screen and the detail output into a textfile as shown in Figures 5 and 6. Grades ‘H’ mean high temperature; ‘M’ is medium temperature and‘L’ is low temperature.Your program must define several functions at least as listed in Table 3. You are also required to applythe concept of parameter passing to these functions. Average of the temperature: 32.3Number of high temperature: 2Number of medium temperature: 20Number of low temperature: 8 Figure 5: Example of output…arrow_forward
- I am confused on how to go about writing this python program.arrow_forwardJava languagearrow_forwardI need help with a java problem: 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. Assume also the last names and first names do not contain whitespaces. - (The rest in described in the attached image) Code - import java.util.Scanner;import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.PrintWriter;import java.io.IOException; public class LabProgram { public static void main(String[] args) throws IOException { Scanner scnr = new Scanner(System.in); /* TODO: Declare any necessary variables here. */ /* TODO: Read a file name from the user and read the…arrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT