Question

In: Computer Science

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 milk money
and exercise responsibility for making change he or she will share
responsibility for the task of managing the money with the assistant
whose skill and expertise shall ensure the successful spending exercise


from typing import Dict, List, TextIO
def job_description(file2: TextIO) -> List[str]:
Write a program such that the file2 is outputted in such a way so that the output is like this so that the line containing '#' is not printed and the non hastag part is written in strings:

The string read from File2.txt is: ['the', 'incumbent', 'will', 'administer', 'the',
'spending', 'of', 'kindergarden', 'milk', 'money', 'and', 'exercise', 'responsibility',
'for', 'making', 'change', 'he', 'or', 'she', 'will', 'share', 'responsibility', 'for',
'the', 'task', 'of', 'managing', 'the', 'money', 'with', 'the', 'assistant', 'whose',
'skill', 'and', 'expertise', 'shall', 'ensure', 'the', 'successful', 'spending',
'exercise']

Solutions

Expert Solution

Raw_code:

from typing import Dict, List, TextIO

# job_description function
def job_description(file2: TextIO)->List[str]:
# reading all lines and storing in data
data:List = file2.readlines()
  
lst = []

# iterating over each line in data
for line in data:
# if line doesn't contains # character
if "#" not in line:
# splitting the each into words and assining to line
line:List = line.split()
# iterating over through line
for word in line:
# appending each word to lst
lst.append(word)
# returing the lst
return lst

# opening the file2.txt
with open("file2.txt") as infile:
# calling the job_desciption function with infile as parameter
# printing the return value
print(job_description(infile))


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 Python program, in a file called StickFigure.py, which, given a value for the total...
Write a Python program, in a file called StickFigure.py, which, given a value for the total height of a stick figure, uses a recursive function to generate the stick figure pattern as shown below. The recursive function is used to print the entire figure. Note that the head, arms and legs stay the same, but the body can be different lengths, depending on what the user enters as the height of the figure. The "body" length is always 3 lines...
(Write/read data) Write a Program in BlueJ to create a file name Excersise12_15.txt if it does...
(Write/read data) Write a Program in BlueJ to create a file name Excersise12_15.txt if it does not exist. Write 100 integers created randomly into the file using text I/O. Integers are separated by spaces in the file. Read data back from the file and display the data in increasing order. After writing the file to disk, the input file should be read into an array, sorted using the static Arrays.sort() method from the Java API and then displayed in the...
Write a C++ program in a file called pop.cpp that opens a file called pop.dat which...
Write a C++ program in a file called pop.cpp that opens a file called pop.dat which has the following data (you’ll have to create pop.dat) AX013 1.0 BX123456 1234.56 ABNB9876152345 99999.99 The data are account numbers and balances. Account numbers are, at most 14 characters. Balances are, at most, 8 characters (no more than 99999.99). Using a loop until the end of file, read an account number and balance then write these to standard output in the following format shown...
Write a program in python to read from a file the names and grades of a...
Write a program in python to read from a file the names and grades of a class of students to calculate the class average, the maximum, and the minimum grades. The program should then write the names and grades on a new file identifying the students who passed and the students who failed. The program should consist of the following functions: a) Develop a getGrades() function that reads data from a file and stores it and returns it as a...
Write a program that reads a file called document.txt which is a text file containing an...
Write a program that reads a file called document.txt which is a text file containing an excerpt from a novel. Your program should print out every word in the file that contains a capital letter on a new line to the stdout. For example: assuming document.txt contains the text C++
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...
In a file called LengthSum.java, write a program that: - Asks the user to enter a...
In a file called LengthSum.java, write a program that: - Asks the user to enter a string. - Asks the user to enter a second string. - Prints out the length of the first string, the length of the second string, and the sum of the two lengths, using EXACTLY the same format as shown below. For example: if the user enters strings "UT" and "Arlington", your program output should look EXACTLY like this: Please enter a string: UT Please...
Step by step in python please Write a program this will read a file (prompt for...
Step by step in python please Write a program this will read a file (prompt for name) containing a series of numbers (one number per line), where each number represents the radii of different circles. Have your program output a file (prompt for name) containing a table listing: the number of the circle (the order in the file) the radius of the circle the circumference the area of the circle the diameter of the circle Use different functions to calculate...
Write a C program that opens a file called "numbers.txt" in writing mode. The program should...
Write a C program that opens a file called "numbers.txt" in writing mode. The program should then read floating point numbers from the keyboard, and write these lines to the opened file one per line, stopping when the number 0 is entered. Your program should check to make sure that the file was opened successfully, and terminate if it was not.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT