Q. Find and write the output of the following python code:
def fun(s):
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)
fun('school2@com')
Answer :-
Output :-
SCHOOLbbbbCOM
>>>
Explanation :-
for good explanation I have write this code in python :-
def fun(s): k = len(s) print ( "k =", k ) m = "" print ( "m =", m ) print ( ) print ( "Now Loop start working" ) print ( ) for i in range(0,k): print ( "i =", i ) if(s[i].isupper()): m = m+s[i].lower() elif s[i].isalpha(): m = m+s[i].upper() else: m = m + 'bb' print("m = ", m) print() print("So for is Output :-") print(m) fun('school2@com')
The output will definitely clear your all doubts.
k = 11
m =
m =
Now Loop start working
i = 0
m = S
i = 1
m = SC
i = 2
m = SCH
i = 3
m = SCHO
m = SCHO
i = 4
m = SCHOO
m = SCHOO
i = 5
m = SCHOOL
m = SCHOOL
i = 6
m = SCHOOLbb
m = SCHOOLbb
i = 7
m = SCHOOLbbbb
m = SCHOOLbbbb
i = 8
m = SCHOOLbbbbC
m = SCHOOLbbbbC
i = 9
m = SCHOOLbbbbCO
m = SCHOOLbbbbCO
i = 10
m = SCHOOLbbbbCOM
m = SCHOOLbbbbCOM
So for is Output :-
SCHOOLbbbbCOM
>>>
SCHOOLbbbbCOM
>>>
Explain please
ReplyDeleteOK : )
DeleteThank you
ReplyDeleteWelcome : )
DeleteSir, is the value of @ not taken
ReplyDeleteYes.
DeleteSir ,is it because there is no input in the function for changing value of special characters like @
ReplyDeleteNo, here special characters convert into 'bb'.
DeleteSir could you plz gives a video explaining it will help us to understand it better way
ReplyDeleteIf(s[i].isupper()): how is this line executed when school2@com is written in lowercase?
ReplyDeleteit execute in "elif s[i].isalpha()" statement.
DeletePost a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )