How can i make the python program define the space | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How can i make the python program define the space

Q=input() Space=0 Word=0 #input "hello world!" for i in Q: if i== "#definition of the space" : Space+=1 else: Word+=1

20th Feb 2020, 2:13 PM
Mohamed El Mujtaba
Mohamed El Mujtaba - avatar
3 Answers
+ 3
if i == ' '
20th Feb 2020, 2:47 PM
R_3-dr
R_3-dr - avatar
+ 2
Mohamed El Mujtaba This code will not count the words that is given as input, rather it only counts the characters (without spaces)
20th Feb 2020, 3:15 PM
Deepraj Baidya
Deepraj Baidya - avatar
+ 1
Deepraj Baidya it can count the words if i add 1 to the spaces after the (if statement) "Num of spaces + 1 = Num of words"
20th Feb 2020, 3:33 PM
Mohamed El Mujtaba
Mohamed El Mujtaba - avatar