Question 01
Open and read from the file line by line. And print out each to the terminal.

Question 02
Open and read the file character by character. If the char is a letter or space, write it into a new file. If it is not a letter or space, skip. At the end of your program, there should be a new file with only letters and spaces left.
(tip: you can either create a list of elements (letters and space) to compare each character or you can use the ord() function to get the ASCII value of each character to see if it is a letter or space, you can find the ASCII table easily searching on google).

Question 03
Write a program that counts the number of words in the file from question 02. Since we only have letters and spaces in the file, you can assume that each word is separated by a space. Hence, you can just count the number of spaces in each line. Also to remember, the last word in a line doesn't have the following space, so you need to handle that by adding an extra word count for each line.

Solution PreviewSolution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

Question 1

# Main method
def main():
    input_file = open('shakespeare.txt')
    for line in input_file:

# Run main method on program execution
if __name__ == "__main__":
$25.00 for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Computer Science - Other Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Upload a file
Continue without uploading

We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats