Question

In: Computer Science

Write a program that opens the file: "Lab6A_Data", reads all the values from the file, and...

Write a program that opens the file: "Lab6A_Data", reads all the values from the file, and calculates the following: A) The number of values in the file B) The sum of all the values in the file (a running total) C) The average of all the values in the file. D) The minimum value. E) The maximum value. F) The range of the data set of values. G) The number of times the value: '357' occurrs in the file. Display the resulting output for Items A-G.

Solutions

Expert Solution

NOTE: Since the programming language is not specified I am doing in python, I am doing all the A-G questions in one program itself, If data is "," specified or any other delimeter then read data at once and use split function to get data and the operations remain same just in the place of appending we use split function

EXPLANATION: Explanation is done in the code itself. Place the file in the same directory where the source file is saved. Other wise keep the absolute path

SOLUTION FOR A-G :

##open the file in read mode
data=open("Lab6A_Data.txt","r")

dataList=[]

##read the data and append it to the list so that it will be easy to calculate
for i in data.readlines():
##if there is \n remove that
if(i.find("\n")):
i.replace("\n","")
##convert it to int while appending so that the operations are done easily
dataList.append(int(i))

##SOLUTION A:
##len is used to get length of the list that means that means count
print("Number of values in file is :",len(dataList))

##SOLUTION B:
##sum is used to calculate sum of items
print("Sum of all the values : ",sum(dataList))

##SOLUTION C:
##average is calculated based as the sum of items by number of items
print("Average of all the values in the file: " ,round(sum(dataList)/len(dataList)),2)

##SOLUTION D:
##min will return the min value in the list
print("Minimum value : " ,min(dataList))

##SOLUTION E:
##max will return the max value in the list
print("Minimum value : " ,max(dataList))

##SOLUTION F:
##max will return the max value in the list
print("Range is from ", min(dataList) ," to ",max(dataList))

##SOLUTION G:
##count function will return number of items in the list
print("The number of time 327 occurs is : ",dataList.count(327))

CODE IMAGE:


  

OUTPUT:

SOURCE FILE WHICH I HAVE TAKEN:


Related Solutions

Write a program which reads an input file. It should assume that all values in the...
Write a program which reads an input file. It should assume that all values in the input file are integers written in decimal. Your program should read all integers from the file and print their sum, maximum value, minimum value, and average. Use the FileClient class here (from a previous reading) as an example. You'll need to create a file to be used as input to test your program, as well. Your program should work whether the integers are separated...
Write a C ++ program which opens a file and reads several numbers, utilizing the fscanf()...
Write a C ++ program which opens a file and reads several numbers, utilizing the fscanf() function. Can you add few comments with explanations what is going on?
File Compare Write a program that opens two text files and reads their contents into two...
File Compare Write a program that opens two text files and reads their contents into two separate queues. The program should then determine whether the files are identical by comparing the characters in the queues. When two nonidentical characters are encountered, the program should display a message indicating that the files are not the same. If both queues contain the same set of characters, a message should be displayed indicating that the files are identical. // Copyright (c) 2013 __Pearson...
● Write a program that reads words from a text file and displays all the words...
● Write a program that reads words from a text file and displays all the words (duplicates allowed) in ascending alphabetical order. The words must start with a letter. Must use ArrayList. MY CODE IS INCORRECT PLEASE HELP THE TEXT FILE CONTAINS THESE WORDS IN THIS FORMAT: drunk topography microwave accession impressionist cascade payout schooner relationship reprint drunk impressionist schooner THE WORDS MUST BE PRINTED ON THE ECLIPSE CONSOLE BUT PRINTED OUT ON A TEXT FILE IN ALPHABETICAL ASCENDING ORDER...
4. Write a program that reads all numbers from a file and determines the highest and...
4. Write a program that reads all numbers from a file and determines the highest and lowest numbers. You must NOT use arrays to solve this problem! Write functions where appropriate. Programming language should be C
● Write a program that reads words from a text file and displays all the words...
● Write a program that reads words from a text file and displays all the words (duplicates allowed) in ascending alphabetical order. The words must start with a letter. Must use ArrayList. THE TEXT FILE CONTAINS THESE WORDS IN THIS FORMAT: drunk topography microwave accession impressionist cascade payout schooner relationship reprint drunk impressionist schooner THE WORDS MUST BE PRINTED ON THE ECLIPSE CONSOLE BUT PRINTED OUT ON A TEXT FILE IN ALPHABETICAL ASCENDING ORDER IS PREFERRED THANK YOU IN ADVANCE...
Java Code using Queue Write a program that opens a text file and reads its contents...
Java Code using Queue Write a program that opens a text file and reads its contents into a queue of characters, it should read character by character (including space/line change) and enqueue characters into a queue one by one. Dequeue characters, change their cases (upper case to lower case, lower case to upper case) and save them into a new text file (all the chars are in the same order as the original file, but with different upper/lower case) use...
Java Code using Stack Write a program that opens a text file and reads its contents...
Java Code using Stack Write a program that opens a text file and reads its contents into a stack of characters, it should read character by character (including space/line change) and push into stack one by one. The program should then pop the characters from the stack and save them in a second text file. The order of the characters saved in the second file should be the reverse of their order in the first file. Ex input file: Good...
Write a program that reads from the external file input.txt, capitalizes all words that begin with...
Write a program that reads from the external file input.txt, capitalizes all words that begin with the letter "a," and then writes them to an external file output.txt (Note: Do not forget to copy the blanks. You may wish to use infile.get and outfile.put in your program.) Output: After the program generates output.txt, the code should display the contents of the file on the screen to verification.
Write a Java program that reads words from a text file and displays all the non-duplicate...
Write a Java program that reads words from a text file and displays all the non-duplicate words in ascending order. The text file is passed as a command-line argument. Command line argument: test2001.txt Correct output: Words in ascending order... 1mango Salami apple banana boat zebra
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT