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

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use 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__":

By purchasing this solution you'll be able to access the following files:

50% discount

$25.00 $12.50
for this solution

or FREE if you
register a new account!

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