Given a string, the task is to write a Python program to count the number of spaces in the string.
Input: "my name is geeks for geeks" Output: number of spaces = 5 Input: "geeksforgeeks" Output: number of spaces=0
- Input string from the user’s
- Initialize count variable with zero
- Run a for loop I from 0 till the length of string
- Inside for loop, check if s[i] == blank, then increment count by 1
- Outside for loop, print count
number of spaces 2
number of spaces 3
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.