My issue
For Loop
For loop can also be used to iterate over a string.
name = “Alice”
for char in name:
print(char)
Here, the For loop iterates over each character in the ‘name’ string.
The ‘char’ variable takes on the value of each character, and it is printed.
The output will be:
A
l
i
c
e
Task
Write a program which does the following:
You are given a string containing some occurrences of the alphabet ‘o’
Count how many o’s are present in the string using a ‘for’ loop and ‘if’ condition and print the count.
My code
# Count how many 'o's are present in the string using a 'for' loop and 'if' condition
string = 'bolloon'
# use this variable to count occurrences of o
count_o = 0
Learning course: Python Programming
Problem Link: For Loop Practice Problem in Python Programming - CodeChef