Answers
If you have any doubts please comment below. Please give upvote if you like this.
Answer : p
there fore the output of following code is "p".
Explanation :
Instalize my_string with "alpha"
after we call the method get_letter_index() with arguments letter "p" and string my_str
Inside method :
for loop itterates from i =0 to length of the given string
check if i =0:
string[0] == "p" false because string[0] is "a" so loop itterate
check if i =1 :
string[1] == "p" false because string[1] is "l" so loop itterate
check if i =2 :
string[2] == "p" true because string[2] is "p" so loop returns i i.e(i=2)
we assign that value to p_index i.e p_index = 2
finally we print the my_string[p_index] i.e the value of my_string[2] is "p"
.