Page 5 - HA
P. 5

Home Assignment

               D) Answer the following questions:
                   1.  What is the output of the following code snippet?
                       num = 1
                       def func():
                              global num
                              num = num + 3
                              print(num, end='  ')
                       func()
                       print(num)

                   2.  What will be the output of the following code:
                       a=10
                       def call():
                              global a
                              b=20
                              a=a+b
                       call()
                       print(a)

                   3.  What will be the output of the following code:
                       def upgrade(a,b=2):
                              a=a+b
                              print(a+b)
                       i,j=10,20
                       upgrade(i,5)
                       upgrade(j)

                   4.  What will be the output of the following 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('vps19$kri')

                   5.  What will be the output of the following code:
                       def Change(P ,Q=60):
                              P=P+Q
                              Q=P-Q
                              print( P,"#",Q)
                              return (P)
                       R=600
                       S=300
                       R=Change(R,S)
                       print(R,"#",S)
                       S=Change(S)
   1   2   3   4   5   6