Question

In: Computer Science

(PYTHON) Write a program that does the following: reads each line from a txt file and...

  1. (PYTHON) Write a program that does the following:
    • reads each line from a txt file and convert it to lowercase
    • counts the number of instances of: the characters 'a', 'e','i','o' and 'u' in the file
    • creates a new file of file type .vowel_profile
    • print outs lines in the file indicating the frequencies of each of these vowels
    • Example input/output files:
      • paragraph_from_wikipedia.txt (sample input) link: https://cs.nyu.edu/courses/fall19/CSCI-UA.0002-007/paragraph_from_wikipedia.txt
      • paragraph_from_wikipedia.vowel_profile (sample output) link: https://cs.nyu.edu/courses/fall19/CSCI-UA.0002-007/paragraph_from_wikipedia.vowel_profile

Please help!

Solutions

Expert Solution

Given below is the code for the question. PLEASE MAKE SURE INDENTATION IS EXACTLY AS SHOWN IN IMAGE.
Please do rate the answer if it helped. Thank you.

inFilename = input('Enter input filename: ')
idx = inFilename.rindex('.')
outFilename = inFilename[:idx] + '.vowel_profile'

try:
   f = open(inFilename, 'r')
except:
   print('ERROR: could not open input file ', filename)
countA = 0
countE = 0
countI = 0
countO = 0
countU = 0
for line in f:
   line = line.lower()
   countA += line.count('a')
   countE += line.count('e')
   countI += line.count('i')
   countO += line.count('o')
   countU += line.count('u')

fout = open(outFilename, 'w')
fout.write('A Frequence:{}\n'.format(countA))
fout.write('E Frequence:{}\n'.format(countE))
fout.write('I Frequence:{}\n'.format(countI))
fout.write('O Frequence:{}\n'.format(countO))
fout.write('U Frequence:{}\n'.format(countU))
fout.close()
print('Please check output file ', outFilename)


Related Solutions

[In Python] Write a program that takes a .txt file as input. This .txt file contains...
[In Python] Write a program that takes a .txt file as input. This .txt file contains 10,000 points (i.e 10,000 lines) with three co-ordinates (x,y,z) each. From this input, use relevant libraries and compute the convex hull. Now, using all the points of the newly constructed convex hull, find the 50 points that are furthest away from each other, hence giving us an evenly distributed set of points.
Write a program that reads a file line by line, and reads each line’s tokens to...
Write a program that reads a file line by line, and reads each line’s tokens to create a Student object that gets inserted into an ArrayList that holds Student objects.  Each line from the file to read will contain two strings for first and last name, and three floats for three test grades.  After reading the file and filling the ArrayList with Student objects, sort the ArrayList and output the contents of the ArrayList so that the students with the highest average...
Write a program in c that reads the content from the file and stores each line...
Write a program in c that reads the content from the file and stores each line in an int array in heap(using dynamic memory allocation). For example, let the file has elements following (we do not know the size of files, it could be above 100,000 and contents of the file and make sure to convert file elements to int): 10067 26789 6789 3467
Write a python program: There is a file called file 2. File2 is a txt file...
Write a python program: There is a file called file 2. File2 is a txt file and I have written the contents of file 2 below in the exact format it was in notepad. # This comment does not make sense # It is just to make it harder # The job description starts after this comment, notice that it has 4 lines. # This job description has 700150 hay system points\\ the incumbent will administer the spending of kindergarden...
Design and write a python program that reads a file of text and stores each unique...
Design and write a python program that reads a file of text and stores each unique word in some node of binary search tree while maintaining a count of the number appearance of that word. The word is stored only one time; if it appears more than once, the count is increased. The program then prints out 1) the number of distinct words stored un the tree, Function name: nword 2) the longest word in the input, function name: longest...
IN PYTHON File Data --- In file1.txt add the following numbers, each on its own line...
IN PYTHON File Data --- In file1.txt add the following numbers, each on its own line (20, 30, 40, 50, 60). Do not add data to file2.txt. Write a program. Create a new .py file that reads in the data from file1 and adds all together. Then output the sum to file2.txt. Add your name to the first line in file2.txt (see sample output) Sample Output Your Name 200 use a main function.
Question: Write a program in python that reads in the file climate_data_2017_numeric.csv and prompts the user...
Question: Write a program in python that reads in the file climate_data_2017_numeric.csv and prompts the user to enter the name of a field (other than Date), and then outputs the highest and lowest values recorded in that field for the month of August. The file climate_data_2017_numeric.csv contains the following fields: Date Minimum temperature (C) Maximum temperature (C) Rainfall (mm) Speed of maximum wind gust (km/h) 9am Temperature (C) 9am relative humidity (%) 3pm Temperature (C) 3pm relative humidity (%) Expected...
Write a program that reads two strings from an input file (The first line is X,...
Write a program that reads two strings from an input file (The first line is X, the second line is Y), compute the longest common subsequence length AND the resulting string. You will need to write 2 methods 1) return LCS length in iterative function // return the length of LCS. L is the 2D matrix, X, Y are the input strings, m=|X|, n=|Y| int lcs_it(int **C, string X, string Y, int m, int n ) 2) return LCS resulting...
Python program: Write a program that reads a text file named test_scores.txt to read the name...
Python program: Write a program that reads a text file named test_scores.txt to read the name of the student and his/her scores for 3 tests. The program should display class average for first test (average of scores of test 1) and average (average of 3 tests) for each student. Expected Output: ['John', '25', '26', '27'] ['Michael', '24', '28', '29'] ['Adelle', '23', '24', '20'] [['John', '25', '26', '27'], ['Michael', '24', '28', '29'], ['Adelle', '23', '24', '20']] Class average for test 1...
Implement in Python a script that does the following: 1) reads input from a supposed file...
Implement in Python a script that does the following: 1) reads input from a supposed file called firstnames_2.txt. 2) processes the input and writes and saves the output to a file. NOTE: Please make sure that the names are written in the outfile with one name on each line no comma ( , ) after the name in the output
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT