Computer Science - Informatics Practices Class XI/XII Python Module Solved Test Part 4

Computer Science - Informatics Practices Class XI/XII Python Module Solved Test  Part 4

Q1. Write the output of following code.

CODE

OUTPUT

a = 10

def fun():

  a=9

  a=a+2

  print(a)

fun()

 


a = 10

def fun():

  a=9

  a=a+2

  print(a)

fun()

print(a)

 


a = 10

def fun():

  global a

  a=a+2

  print(a)

fun()

print(a)

 


a = 10

def fun():

  global a

  a=a+2

  print(a)

print(a)

fun()

 

 

 


Q2. Write the output of the following:
a = 10
def fun():
global a
a=a+2
print(a)
fun()
print(a)

Q3. Write the output of the following
a = 10
print(a+3)
def fun():
global a
a=a+2
print(a)
fun()
print(a)

Q4. Write the output of the following.
a = 10
print(a*3)
def fun():
print(a)
fun()
print(a)

Q5. Write the output of the following.
a = 10
print(a*3)
def fun(a):
print(a*2)
fun(a)
print(a)

Q6. Write the output of the following:
a = 10
print(a*3)
def fun1(a):
def fun2():
print("hello")
print(a*2)
fun2()
fun1(a)
print(a)

Q7. Write the output of the following.
a = 10
print(a*3)
def fun1(a):
def fun2():
print("hello")
print("hello")
print(a*2)
fun2()
fun1(a)
print(a)

Q8. Write the output of the following.
a = 10
print(a*3)
def fun1(a):
def fun2():
print("hello")
print("hello")
print(a*2)
fun2()
print("hello")
print("hello")
fun1(a)
print(a)



                                            SOLUTION

Q1. Write the output of following code.

CODE

OUTPUT

a = 10

def fun():

  a=9

  a=a+2

  print(a)

fun()

 

11

a = 10

def fun():

  a=9

  a=a+2

  print(a)

fun()

print(a)

 

11

10

a = 10

def fun():

  global a

  a=a+2

  print(a)

fun()

print(a)

 

12

12

a = 10

def fun():

  global a

  a=a+2

  print(a)

print(a)

fun()

 

 

10

12 


Q2. Write the output of the following:
a = 10
def fun():
global a
a=a+2
print(a)
fun()
print(a)

Ans
10
12

Q3. Write the output of the following
a = 10
print(a+3)
def fun():
global a
a=a+2
print(a)
fun()
print(a)
Ans.
13
10
12

Q4. Write the output of the following.
a = 10
print(a*3)
def fun():
print(a)
fun()
print(a)

Ans.
30
10
10

Q5. Write the output of the following.
a = 10
print(a*3)
def fun(a):
print(a*2)
fun(a)
print(a)

Ans.
30
20
10

Q6. Write the output of the following:
a = 10
print(a*3)
def fun1(a):
def fun2():
print("hello")
print(a*2)
fun2()
fun1(a)
print(a)

Ans.
30
20
hello
10

Q7. Write the output of the following.
a = 10
print(a*3)
def fun1(a):
def fun2():
print("hello")
print("hello")
print(a*2)
fun2()
fun1(a)
print(a)

Ans.
30
hello
20
hello
10

Q8. Write the output of the following.
a = 10
print(a*3)
def fun1(a):
def fun2():
print("hello")
print("hello")
print(a*2)
fun2()
print("hello")
print("hello")
fun1(a)
print(a)

Ans.
30 hello hello 20 hello hello 10

No comments:

Post a Comment

Most Recently Published

File Handling Test 6

 File Handling Test 6 Q1 . Do we need to use the close() function when we use 'with' statement to open a file? Q2. Which mode you wi...

CS - IP Assignment/Worksheet