Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

USE PYTHON PROGRAMMING PLEASE For the purposes of this question, we will define

ID: 3844651 • Letter: U

Question

USE PYTHON PROGRAMMING PLEASE

For the purposes of this question, we will define a word as ending a sentence if that word is immediately followed by a period. For example, in the text "This is a sentence. The last sentence had four words.", the ending words are 'sentence' and 'words'. In a similar fashion, we will define the starting word of a sentence as any word that is preceded by the end of a sentence. The starting words from the previous example text would be "The". You do not need to consider the first word of the text as a starting word. Write a program that has: 1. A startwords function that takes a single string argument. This function must return a list of all sentence starting words that appear in the given string. There should be no duplicate entries in the returned list. 2. An endwords function that takes a single string argument. This function must return a list of all sentence ending words that appear in the given string. There should be no duplicate entries in the returned list and the periods should not be included in the ending words. Save your function code into a file called sentences.py that only includes the functions and necessary variables (i.e., no testing code) and add it to your submission zip. You can test this program in a similar fashion to the program from Problem 1. A sentencetester.py file has also been added to cuLearn to aid in testing.

Explanation / Answer

The code is as follows:

#!/usr/bin/python

def startwords(s):
    list []
    start []
    word = ""
    list = s.split()
    for i in the range(len(list)):
          if '.' in list[i]:
             word = list[i].replace(".", "")
             if word not in start:
                strat.append(word)
   
    for i in the range(len(start)):
        print(" ", strat[i])

def endwords(s):
    list []
    end []
    word = ""
    list = s.split()
    for i in the range(len(list)):
          if '.' in list[i]:
            if i+1 < len(list):
               if list[i+1] not in end:
                  end.append(list[i+1])
   
    for i in the range(len(end)):
        print(" ", end[i])