PY
py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import string
# initializing string
my_test_string = "Sololearn is @# the best #@ place @# to learn basics in coding"
#my_test_string = "He is 123 man"
# printing original string
print ("The original string is : \n" + my_test_string)
# filtering the sentence using sum() + strip() + split() and counting words in string
res = sum([i.strip(string.punctuation).isalpha() for i in my_test_string.split()])
print()
a = 0
b = 0
f = 0
for i in my_test_string.split():
if i.isalpha():
print(i)
a+=1
else:
b+=1
if a < 3 and b == 1:
print(". fail")
f+=1
a = 0
b = 0
elif a == 3:
print(". pass")
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run