should be done in python please help
#The Question can be answered in two ways.
#1)Using general calculation
#2)Using numpy module
#First Approach
from math import sqrt
#opening floats.txt in read mode
fp=open("floats.txt","r")
floats=[]
for line in fp.readlines():
#Converting each line in txt file to float
floats.append(float(line))
#Closing fp
fp.close()
minimum=min(floats)
maximum=max(floats)
total=sum(floats)
average=total/len(floats)
"""
The forumla for standard deviation is
sqrt(sum((x_i - average(x))**2)/n)
"""
difference=0
for x in floats:
difference+=abs(x-average)**2
std=sqrt(difference/len(floats))
#Opening stats.txt in write mode
fp=open("stats.txt","w")
fp.write(str(minimum)+"\n")
fp.write(str(maximum)+"\n")
fp.write(str(total)+"\n")
fp.write(str(average)+"\n")
fp.write(str(std)+"\n")
#Closing "stats.txt"
fp.close()
#Second Approach
import numpy as np
from math import sqrt
#opening floats.txt in read mode
fp=open("floats.txt","r")
floats=[]
for line in fp.readlines():
#Converting each line in txt file to float
floats.append(float(line))
#Closing fp
fp.close()
floats=np.array(floats)
minimum=floats.min()
print(minimum)
maximum=floats.max()
print(maximum)
total=floats.sum()
print(total)
average=floats.mean()
print(average)
std=floats.std()
print(std)
#Opening stats.txt in write mode
fp=open("stats.txt","w")
fp.write(str(minimum)+"\n")
fp.write(str(maximum)+"\n")
fp.write(str(total)+"\n")
fp.write(str(average)+"\n")
fp.write(str(std)+"\n")
#Closing "stats.txt"
fp.close()
should be done in python please help 9) A file named floats.txt contains a bunch of...
Create a python code named LetterCount with a text file named words.txt that contains at least 100 words in any format - some words on the same line, some alone (this program involves no writing so you should not be erasing this file). Then create a program in the main.py that prompts the user for a file name then iterates through all the letters in words.txt, counting the frequency of each letter, and then printing those numbers at the end...
*PYTHON EXPERTS ONLY PLEASE* Please provide the answer coded in Python using comments to explain code function. Good answers will be rated with thumbs up! Please answer both parts. Thank you for your time. Question 3 - Suppose you have a file named numbers.csv which contains a bunch of integers, five per line of text, separated by commas. Write code below that will open the _le, read the numbers from it, and print the sum of all the even numbers...
Could anyone please help with this Python code assignment? In this programming assignment you are to create a program called numstat.py that reads a series of integer numbers from a file and determines and displays the following: The name of the file. The sum of the numbers. The count of how many numbers are in the file. The average of the numbers. The average is the sum of the numbers divided by how many there are. The maximum value. The...
USING PYTHON PROGRAMMING LANGUAGE 15. Write code to open a file named data.txt, which contains 3 numbers, and print the sum of those numbers to the console 16. Write code that opens a file named words.txt containing an essay, and the prints out the SECOND word in the file to the console
In python Attached is a file called sequences.txt, it contains 3 sequences (one sequence per line). Also attached is a file called AccessionNumbers.txt. Write a program that reads in those files and produces 3 separate FATSA files. Each accession number in the AccessionNumbers.txt file corresponds to a sequence in the sequences.txt file. Remember a FASTA formatted sequence looks like this: >ABCD1234 ATGCTTTACGTCTACTGTCGTATGCTTTACGTCTACTGACTGTCGTATGCTTACGTCTACTGTCG The file name should match the accession numbers, so for 1st one it should be called ABCD1234.txt. Note:...
(Python 3) Write a program that reads the contents of a text file. The program should then create a dictionary in which the keys are individual words found in the file and the values are the number of times each word appears and a list that contains the line numbers in the file where the word (the key) is found. Then the program will create another text file. The file should contain an alphabetical listing of the words that are...
PYTHON write a program that will open a file named data.txt and read each line of the file one at a time. Each line should be printed to the screen along with a line number
1.Write a python program that writes a series of random numbers to a file named random.txt. Each random number should be in the range of 1 through 300. The application should let the user specify how many random numbers the file will hold. 2. Write another program that reads the random numbers from the random.txt file, displays the numbers, then displays the following data: I. The total of the numbers II. The number of random numbers read from the file
Could anyone help add to my python code? I now need to calculate the mean and median. In this programming assignment you are to extend the program you wrote for Number Stats to determine the median and mode of the numbers read from the file. You are to create a program called numstat2.py that reads a series of integer numbers from a file and determines and displays the following: The name of the file. The sum of the numbers. The...
Description: Create a program called numstat.py that reads a series of integer numbers from a file and determines and displays the name of file, sum of numbers, count of numbers, average of numbers, maximum value, minimum value, and range of values. Purpose: The purpose of this challenge is to provide experience working with numerical data in a file and generating summary information. Requirements: Create a program called numstat.py that reads a series of integer numbers from a file and determines...