Showing posts with label Output Based. Show all posts
Showing posts with label Output Based. Show all posts

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

Python : Looping Statement Test 4

Python : Looping Statement Test 4

Q1. What is the use of range function in python?

Q2. Name three jump statements in python and explain any one.

Q3. Write the output of the following program.

Code

Output

x = "123"

for i in x:

  print(i)

 

 

i=8

while True:

  if i%3==0:

    break

  print("A")

 

 

i=9

while True:

  if i%3==0:

    break

  print("A")

 

 

i=0

while i<3:

  print(i)

  i=i+1

else:

  print(0)

 

 

i=0

while i<3:

  print(i)

  i=i+1

print(0)

 

 

i=0

while i<3:

  print(i)

  i=i+1

  print(0)

 

 

i=2

for x in range(i):

  i+=1

  print(i)

  print(i)

 

 

i=2

for x in range(i):

  x+=1

  print(x)

print(x)

 

 

i=2

for x in range(i):

  x+=1

  print(x)

  print(x)

 

 

i=100

while i<57:

  print(i)

  i+=5

 

 

i=100

while i>57:

  print(i+1)

  i+=5

 

 

 

Q4. Write the output and convert it into for loop.

i=100

while i>57:

               print(i)

               i-=5

 

 

Solution of Q3.

Code

Output

x = "123"

for i in x:

  print(i)

 

1

2

3

i=8

while True:

  if i%3==0:

    break

  print("A")

 

Infinite loop

i=9

while True:

  if i%3==0:

    break

  print("A")

 

No Output

i=0

while i<3:

  print(i)

  i=i+1

else:

  print(0)

 

0

1

2

0

i=0

while i<3:

  print(i)

  i=i+1

print(0)

 

0

1

2

0

i=0

while i<3:

  print(i)

  i=i+1

  print(0)

 

0

0

1

0

2

0

i=2

for x in range(i):

  i+=1

  print(i)

  print(i)

 

3

3

4

4

i=2

for x in range(i):

  x+=1

  print(x)

print(x)

 

1

2

2

i=2

for x in range(i):

  x+=1

  print(x)

  print(x)

 

1

1

2

2

i=100

while i<57:

  print(i)

  i+=5

 

No Output

i=100

while i>57:

  print(i+1)

  i+=5

 

Infinite loop

 


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