-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWordCounter.py
More file actions
17 lines (13 loc) · 818 Bytes
/
WordCounter.py
File metadata and controls
17 lines (13 loc) · 818 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#A function to count all the characters present in the input string including special characters and spaces
def CHARACTER_COUNT(String):
return len(String)
# A function to count the number of words present in the input string
def WORD_COUNT(String):
words = String.split(' ') # Split function with a space character splits the input string at space character
return len(words)
# Assumption1 - EACH CONSECUTIVE WORD IS SEPARATED BY A SPACE CHARACTER
# Assumption2 - WHEN SENTENCE ENDS WITH A '.' OR ANY OTHER PUNCTUATIONS, A SPACE IS GIVEN WHILE STARTING NEXT WORD
# Main function
sentence = input("Enter sentence(s) to begin Count : ")
print("Number of characters : ", CHARACTER_COUNT(sentence))
print("Number of words in the sentence : ", WORD_COUNT(sentence))