Question: This PYTHON QUESTION says : SyntaxError: 'return' outside function(SentenceCapitalizer.py, line 28) 28 return lastcharacter def main(): position = 1 # Initialize position variable value to1.

This PYTHON QUESTION says :

  • SyntaxError: 'return' outside function(SentenceCapitalizer.py, line 28)
  • 28 return lastcharacter

def main():
position = 1 # Initialize position variable value to"1".
statement = input("Enter sentence to be capitalized:") # Input takes the user entered sentence and stores in"statement" variable.
word = statement.split() # word spliter.
is_capital(word[0]) # is_capital function call to check first wordis capital or not.
lastcharacter = endchecker(word[0]) # calls endchecker function andstores the return value of function in lastcharactervariable.
while position < len(word): # while loop to check the user inputsentence.
if lastcharacter == "True": # If last character istrue than call is_capital function.
is_capital(word[position]) # functioncall with word[postion] as segment.
else: # Else statement
print(word[position],end=' ') # Displays the word inthat position
lastcharacter = endchecker(word[position]) # calls endcheckerfunction with input segment and stores the value in lastcharactervariable.
position += 1 # increment the position value by 1.
print("") # goes to next line
def is_capital(partofsentence): # is_capital functiondefinition
print(partofsentence[:1].upper(),end='') # printfirst letter of word as upper case.
print(partofsentence[1:],end=' ') # print remaining letters of thatword.
def endchecker(partofsentence): # endchecker functiondefinition
lastcharacter = "False" # lastcharacter isfalse
# Check the condition if the sentence contains .,?,! as lastcharacters of a word then end of sentence i.e,lastcharactervariable becomes true and next word first character will becapitalized.
if '.' in partofsentence:
lastcharacter = "True"
elif '!' in partofsentence:
lastcharacter = 'True'
elif '?' in partofsentence:
lastcharacter = 'True'
# function endchecker returns "lastcharacter"
return lastcharacter
main()

Step by Step Solution

3.47 Rating (167 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Answer This is a syntax error a simple indentation error in endchecker function Since here return function is not aligned to the indent of the endchecker function please see the screen shot of the cor... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Electrical Engineering Questions!