WeCP Python Coding Question 1: Sentence counter
Problem
statement-:
We know
sentences are terminated with certain punctuations like ‘.’,’!’,’?’, whereas
there are several punctuations which don’t terminate the punctuations. Given
for a paragraph, write a code to find out how many sentences are there.
Note that,
‘…’,’,’,’-‘ these don’t terminate a sentence.
Constraints:
Number of
words in the paragraph<=10^8
Input
Format:
Paragraph
ended with an enter.
Output
Format:
Single
Integer denoting number of sentences.
Sample
Input:
Hello! How
are you? Last time I saw you… you were nervous.
Sample
Output:
3
Explanation:
The three
sentences are:
hello!
How are you?
Last time I
saw you… you were nervous.
Program :
# WeCP
Python Coding Question 1 : Sentence Counter
def
SentenceCount(L):
ans=0
for w in L:
if w[len(w)-1]=='!' or
w[len(w)-1]=='?':
ans+=1
elif(w=="."):
ans+=1
elif len(w)>1:
if w[len(w)-1]=='.' and
w[len(w)-2]!='.':
ans+=1
return ans
def main():
L=list(map(str,input().split()))
result = SentenceCount(L);
print(result)
if __name__
== "__main__":
main()
For
Output Check the Video :
Comments
Post a Comment