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

Lines 43 til the end say: #If your function works correctly, this will originall

ID: 3707933 • Letter: L

Question

Lines 43 til the end say:

#If your function works correctly, this will originally
#print:
#empty
#character
#word
#sentence
#paragraph
#page
print(string_type(""))
print(string_type("!"))
print(string_type("CS1301."))
print(string_type("This is too many cases!"))
print(string_type("There's way too many ostriches. Why are there so many ostriches. The brochure said there'd only be a few ostriches."))
print(string_type("Paragraphs need to have multiple sentences. It's true. However, two is enough. Yes, two sentences can make a paragraph."))

Coding Problem 4.2.5 (External resource) (0.0/3.0 points) StrType.py SubmitRun Grades Reset empty character sentence 2#string argument and determines what type of string it is 3 # -If the string is empty, return "empty" 4# -If the string is a single character, return "character" 5# -If the string represents a single word, return "word" 6 # The string is a single word if i . 7# -If the string is a whole sentence, return "sentence" 8 # The string is a sentence if it contains spaces, but 9 # at most one period 10 # -If the string is a paragraph, return "paragraph". The t has no spaces 11# 5tring is a paragraph if it contains both spaces and 12 # multipleper we won't worry about other - 13 # punctuation marks) 14# -If the string is multiple paragraphs, return "page" ing is a paragraph if 15 # The str 16 # characters (" ' it contains any newline 17 #Hint: think carefully about what order you 18 #these conditions in. #Hint 2: remember, there exists a count() method that 19#counts the number of times a string appears in 29 #string. For example, "blah blah blah" , count( "blah") should check another 21 #would return 3 22 ttWrite your function here: 23 def string_type (s): if len(s)0: elif len (s)--1: periodCount for c in s: return empty 26 27 return "character" else: spaceCounte 32 if c--n if c ifc- return "page periodcount-periodCount+1 spaceCount spaceCount 1 37 return"word if periodcount > and spacecount>e: return "paragraph return "sentence"

Explanation / Answer

def string_type(s): if len(s) == 0: return "empty" elif len(s) == 1: return "character" elif s.count(' ') == 0: return "word" elif s.count('.') 1: if s.count(' ') > 0: return "page" else: return "paragraph" print(string_type("")) print(string_type("!")) print(string_type("CS1301.")) print(string_type("This is too many cases!")) print(string_type("There's way too many ostriches. Why are there so many ostriches. The brochure said there'd only be a few ostriches.")) print(string_type("Paragraphs need to have multiple sentences. It's true. However, two is enough. Yes, two sentences can make a paragraph."))
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote