Computer Science, asked by mitalirathore39, 4 months ago

Find and write the output of the following Python code: def Display(str): m="" for i in range(0,len(str)): if(str[i].isupper()): m=m+str[i].lower() elif str[i].islower(): m=m+str[i].upper() else: if i%2==0:
m=m+str[i-1] else:
m=m+"#"
print(m) Display('[email protected]')
2

Answers

Answered by madhalaimuthucharlas
2

Answer:

The output is

fun#

fun#pTHONn#

Answered by dreamrob
9

Given Program :

def Display(str):  

   m=""  

   for i in range(0,len(str)):  

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

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

       elif str[i].islower():  

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

       else:  

           if i%2==0:

               m=m+str[i-1]  

           else:

               m=m+"#"

   print(m)  

Display('[email protected]')

Output :

fUN#pYTHONn#.

Explanation :

Loop will execute from 0 to length

[email protected]

length = 13

So, loop will start from i = 0 till i < 13

Then we will check for conditions :

1) F : upper case

Upper case will be converted to lower case

m = "" + f

So, m = f

2) u : lower case

Lower case will we converted to upper case

m = f + U

So, m = fU

3) n : lower case

m = fU + N

So, m = fUN

4) @ : neither upper case of lower case

We will move to else block

if i%2==0:          

3%2 == 0 , false , because remainder will be 1

m = fUN + #

So, m = fUN#

5) P : upper case

m = fUN# + p = fUN#p

6) y : lower case

m = fUN#p + Y = fUN#pY

7) t : lower case

m = fUN#pY + T = fUN#pYT

8) h : lower case

m = fUN#pYT + H = fUN#pYTH

9) o : lower case

m = fUN#pYTH + O = fUN#pYTHO

10) n : lower case

m = fUN#pYTHO + N = fUN#pYTHON

11) 3 : neither upper case or lower case

i = 10

10 % 2 == 0 , true

So, m=m+str[i-1]                             str[i-1] = str[10 - 1] = str[9] = n

m = fUN#pYTHON + n

So, m = fUN#pYTHONn

12) . : neither upper case or lower case

11 % 2 == 0 , false                      

m = fUN#pYTHONn + #

So, m = fUN#pYTHONn#

13) 0 : neither upper case or lower case

i = 12

12 % 2 == 0 , true

So, m=m+str[i-1]                             str[i-1] = str[12 - 1] = str[11] = .

m = fUN#pYTHONn# + .

So, m = fUN#pYTHONn#.

So, final output is fUN#pYTHONn#.

Similar questions