Computer Science, asked by bimalpahari179, 10 months ago

Write a program to count number of ‘s’ in the string ‘successor’.

Answers

Answered by Equestriadash
7

string = "successor"

count = 0

for i in string:

 if i == "s":

   count = count + 1

print("s in present in 'successor'", count, "times.")

Once the loop starts, the assigned variable 'i', traverses through the string range, and checks for its equivalent character, s. If it results true, the count variable increments by one.

A for loop is an iteration statement, that does repeated-checking, for a given condition. It consists of a variable that changes its value during each loop and a range, in which the variable will take up different values.

Attachments:
Similar questions