Computer Science, asked by wwwkingdomdom, 2 months ago

Write output of the following code:

s = “school12@com”

k = len(s)

m = “ ”

for i in range(0,k):

if (s[i].isupper()):

m = m + s[i].lower()

elif s[i].isalpha():

m = m + s[i].upper()

else:

m = m + “bb”

print(m)​

Answers

Answered by mandalshubhamkumar85
1

Answer:

b9. Recently you saw on a news channel that a

Explanation:

9. Recently you saw on a news channel that a

Answered by allysia
5

Answer:

The output will be:

______

SCHOOLbbbbbbCOM

________

Explanation:

Let's assign the codes specific line number just for the sake of making explanation easy.

___________

1. s="school12@com"

2. k = len(s)

3. m = ""

4. for i in range(0,k):

5.    if (s[i].isupper()):

6.        m = m + s[i].lower()

7.    elif s[i].isalpha():

8.        m = m + s[i].upper()

9.    else:

10.        m = m + "bb"  

11. print(m)

___________

Some terms to understand in the code:

a) len(a) will find length of a.

b) a.isupper() will check whether the alphabet is capital or not.

c) a.isalpha() will check whether the letter is alphabet or not.

d) The statements under condition will run only when the value staisfies the condition.

e) s[i] here has been used to find the letter on i th index of s string and i is controlled by a loop.

f) m=m + "something" is concatenating "something" to previous value of m and save it as m. Like, m="king" , now m = m+"dom" will return m = "king"+"dom" ="kingdom".

Back to code

Line 2: k = len(s) which = 12.

So the loop will be running 0 to 12 times,

Now as the code goes,

if the s[i] is capital, the program will convert it to small letter and add it in  m(empty string), if it's alphabet it will be converted to capital letter and concatenated to m and if none of these 2 conditions are satisfied it will simply add "bb" to m.

Now,

when i = 0,

s[0].upper = False, since the first letter isn't capital, so the next condition is checked,

s[0] is an alphabet whose values is "s", so it is capitalized and concatenated to m so that m = "S"

Else doesn't runs since the one of the condition is already satisfied.

when i= ,

s[i]="c"

again,

s[1].isupper = False but s[1].isalpha = True,

therefore m="S"+"C" = "SC"

The loop goes on,

when i=6,

s[i].isupper = False,

s[i].isalpha= False so else runs,

and "bb" is added to new m so that m="SCHOOLbb"

This goes on till end and you get the mentioned output.

Similar questions