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

(ii) bccabc

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 31.jpg

Output:

bccabc

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, Social Science, Physics, Chemistry, Computer Science at Teachoo.