46.9k views
5 votes
Write in Python

Write a loop that counts the number of space characters that appears in the string referenced as mystring.

User RicardoS
by
6.1k points

1 Answer

5 votes

Answer:

# create function that

# return space count

def check_space(string):

# counter

count = 0

# loop for search each index

for i in range(0, len(string)):

# Check each char

# is blank or not

if string[i] == " ":

count += 1

return count

# driver node

string = "Welcome to geeksforgeeks"

# call the function and display

print("number of spaces ",check_space(string))

Step-by-step explanation:

User Suhel
by
7.7k points