write a loop that prints out the index of every 'i' in 'mississippi
Answers
Answered by
5
Program:
#string
x="mississippi"
#char to match
char="i"
#count variable
count=0
#using loop to iterate over string
for i in x:
#if statement to check the condition
if (i == char):
#displaying the index of i
print("index of i is - ", count)
#incrementing count with 1
count=count+1
Output:
index of i is - 1
index of i is - 4
index of i is - 7
index of i is - 10
Explanation:
- string "mississippi" is stored in variable x.
- char variable stores "i".
- Initializing the count variable to 0. The count will store the index of i in the string.
- Using a for loop to iterate over the string x.
- if statement will check whether the i == char.
- the print function is used to display the value of the count variable.
- incrementing the value of the count variable.
Learn More:
- what is indexing: https://brainly.in/question/3356261
- index number: https://brainly.in/question/9130162
Similar questions