Computer Science, asked by ferozahmad903, 4 months ago

Consider the following code : 3

string =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)

What will be the output produced if input is : (i) aabbcc (ii) aaccbb (iii) abcc ?​

Answers

Answered by Anonymous
6

Answer:

hi...

there are many errors in your code...

but after correcting all the errors you will get the following output....

Explanation:

i)

bncc

4

ii)

cc

4

iii)

cc

4

hope it helps you ☺️

Answered by vishakasaxenasl
0

Answer:

Input is : (i) aabbcc

Output: bbcc 3

Input is : (ii) aaccbb

Output: ccbb 3

Input is : (iii) abcc

Output:  cc 3

Explanation:

The given code block is:

string =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)

The count variable is initialized to 3.

If the first character of the string is 'a' then the string will be sliced from the second index to the last.

For input : (i) aabbcc

  • The first character of the string 'a' so string is sliced from the second index to the last.
  • Output string becomes bbcc and the count is 3

For input: (ii) aaccbb

  • The first character is again 'a' one so the sting is sliced from the second index to the last.
  • Output string becomes ccbb and the count is 3.

For input: (iii) abcc

  • The first character is again 'a' so slicing from the second index to the last.
  • The output string is cc and the count is 3.

#SPJ2

Similar questions