Question

In: Computer Science

Write a Python program called “exam.py”. The input file, “input.txt”, is given to you in the...

  1. Write a Python program called “exam.py”. The input file, “input.txt”, is given to you in the Canvas exam instructions.
  2. Name your output file “output.txt”.
  3. Ensure the program consists of a main function and at least one other function.
  4. Ensure the program will read the input file, and will output the following information to the output file as well as printing it to the screen:
  • output the text of the file to screen
  • output the number of words in the file
  • output the number of sentences in the file
  • output the first sentence in the file
  • output the last sentence in the file
  • output the length of the first sentence
  • output the length of the last sentence
  • output the first word in the file
  • output the first letter in the file
  • output the last word in the file
  • output the last letter in the file

The input file, “input.txt” is called parse Text.txt

Four score and seven years ago our fathers brought forth on this continent, a new nation, conceived in Liberty, and dedicated to the proposition that all men are created equal. Now we are engaged in a great civil war, testing whether that nation, or any nation so conceived and dedicated, can long endure. We are met on a great battle-field of that war. We have come to dedicate a portion of that field, as a final resting place for those who here gave their lives that that nation might live. It is altogether fitting and proper that we should do this. But, in a larger sense, we can not dedicate — we can not consecrate — we can not hallow — this ground. The brave men, living and dead, who struggled here, have consecrated it, far above our poor power to add or detract. The world will little note, nor long remember what we say here, but it can never forget what they did here. It is for us the living, rather, to be dedicated here to the unfinished work which they who fought here have thus far so nobly advanced. It is rather for us to be here dedicated to the great task remaining before us — that from these honored dead we take increased devotion to that cause for which they gave the last full measure of devotion — that we here highly resolve that these dead shall not have died in vain — that this nation, under God, shall have a new birth of freedom — and that government of the people, by the people, for the people, shall not perish from the earth.

Solutions

Expert Solution

# function to read the file and return the data
def readFile(filename):
    file = open(filename, 'r')
    data = file.read()
    return data

# main function
def main():

    # call function to get data of file
    data = readFile('input.txt')
    outFile = open('output.txt', 'w')
    print(data)


    # now display and write the data one by one

    words = data.split()
    print('Number of words:', len(words))
    outFile.write('Number of words: {}'.format(len(words)))

    sentences = data.split('.')
    sentences = sentences[:len(sentences)-1]
    print('Number of sentences:', len(sentences))
    outFile.write('Number of sentences:'.format(len(sentences)))

    print('First sentence:', sentences[0])
    outFile.write('First sentence: {}'.format(sentences[0]))

    print('Last sentence:', sentences[len(sentences)-1])
    outFile.write('Last sentence: {}'.format(sentences[len(sentences)-1]))

    print('Length of first sentence:', len(sentences[0]))
    outFile.write('Length of first sentence: {}'.format(len(sentences[0])))

    print('Length of last sentence:', len(sentences[len(sentences)-1]))
    outFile.write('Length of last sentence: {}'.format(len(sentences[len(sentences)-1])))

    print('First word:', words[0])
    outFile.write('First word: {}'.format(words[0]))

    print('Last word:', words[len(words)-1])
    outFile.write('Last word: {}'.format(words[len(words)-1]))

    print('First letter:', words[0][0])
    outFile.write('First letter: {}'.format(words[0][0]))

    print('Last letter:', words[len(words)-1][0])
    outFile.write('Last letter: {}'.format(words[len(words)-1][0]))



# call main function
if __name__ == "__main__" :main()

FOR HELP PLEASE COMMENT
THANK YOU.


Related Solutions

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 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...
Write a C++ pgm which 1.reads an input file named 'input.txt' 2.content of input.txt are not...
Write a C++ pgm which 1.reads an input file named 'input.txt' 2.content of input.txt are not known to you 3.copies content of input file into an output file named 'output.txt' 4.contents of output.txt should be exactly the same as contents of input.txt 5.the user should be given a choice to select input and output file in any folder 6.remember to check that input file opened successfully
[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 that reads a file, input by the user, containing one word/token per...
Write a Python program that reads a file, input by the user, containing one word/token per line with an empty line between sentences. The program prints out the longest word found in the file along with its length.
PYTHON Write a python program that encrypts and decrypts the user input. Note – Your input...
PYTHON Write a python program that encrypts and decrypts the user input. Note – Your input should be only lowercase characters with no spaces. Your program should have a secret distance given by the user that will be used for encryption/decryption. Each character of the user’s input should be offset by the distance value given by the user For Encryption Process: Take the string and reverse the string. Encrypt the reverse string with each character replaced with distance value (x)...
For c language. I want to read a text file called input.txt for example, the file...
For c language. I want to read a text file called input.txt for example, the file has the form. 4 hello goodbye hihi goodnight where the first number indicates the n number of words while other words are separated by newlines. I want to store these words into a 2D array so I can further work on these. and there are fewer words in the word file than specified by the number in the first line of the file, then...
Python: Write a program that asks the user for the name of a file. The program...
Python: Write a program that asks the user for the name of a file. The program should display the contents of the file line by line.
Write a C program that, given a file named Program_2.dat as input, determines and prints the...
Write a C program that, given a file named Program_2.dat as input, determines and prints the following information: The number of characters in the file. The number of uppercase letters in the file. The number of lowercase letters in the file. The number of words in the file. The number of lines in the file. Your program should assume that the input file, Program_2.dat, may contain any text whatsoever, and that text might be, or might not be, the excerpt...
write a program in c++ that opens a file, that will be given to you and...
write a program in c++ that opens a file, that will be given to you and you will read each record. Each record is for an employee and contains First name, Last Name hours worked and hourly wage. Example; John Smith 40.3 13.78 the 40.3 is the hours worked. the 13.78 is the hourly rate. Details: the name of the file is EmployeeNameTime.txt Calculate the gross pay. If over 40 hours in the week then give them time and a...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT