What will be the output of the following code if the input is A

(i) abbcca

string = raw_input(“Enter a string:”)

count = 3

while true:

if string[0] == ‘a’:

string = string[2:]

elif string[-1] == ‘b’:

string = string [:2]

else:

count+=1

break

print string

print count

 

Answer:

Untitled 27.jpg

Output: 

bcca

4

Go Ad-free
Davneet Singh's photo - Co-founder, Teachoo

Made by

Davneet Singh

Davneet Singh has done his B.Tech from Indian Institute of Technology, Kanpur. He has been teaching from the past 14 years. He provides courses for Maths, Science and Computer Science at Teachoo