1 parent b37ed02 commit 9b586daCopy full SHA for 9b586da
1 file changed
Count_Words.py
@@ -0,0 +1,35 @@
1
+# Problem Statement
2
+# For a given input string(str),
3
+# find and return the total number of words present in it.
4
+# It is assumed that two words will have only a single space in between.
5
+# Also, there wouldn't be any leading and trailing spaces in the given input string.
6
+
7
+# Sample Input 1:
8
+# Coding Ninjas!
9
10
+# Sample Output 1:
11
+# 2
12
13
+# Sample Input 2:
14
+# this is a sample string
15
16
+# Sample Output 2:
17
+# 5
18
19
+from os import *
20
+from sys import *
21
+from collections import *
22
+from math import *
23
+from sys import stdin
24
25
26
+def countWords(string) :
27
+ return len(string.split())
28
29
30
+#main
31
+string = stdin.readline().strip();
32
+count = countWords(string)
33
34
+print(count)
35
0 commit comments