QUIZ ON : PROGRAMMING AND PROBLEM SOLVING THROUGH PYTHON - FUNCTIONS IN PYTHON

FUNCTIONS IN PYTHON

00:00:00

What will be the output of the following Python code?

def san(x):      print(x+1)  x=-2  x=4  san(12)

Option A. 13
Option B. 10
Option C. 2
Option D. 5
True Answer A

Explanation :
The value passed to the function san() is 12. This value is incremented by one and printed. Hence the output of the code shown above is 13.

What will be the output of the following Python code?

def san(x):      print(x+1)  x=-2  x=4  san(12)

Question No# : 01 out of 20



What will be the output of the following Python code?

def foo(fname, val):      print(fname(val))  foo(max, [1, 2, 3])  foo(min, [1, 2, 3])

Option A. 3 1
Option B. 1 3
Option C. error
Option D. none of the mentioned
True Answer A

Explanation :
It is possible to pass function names as arguments to other functions.

What will be the output of the following Python code?

def foo(fname, val):      print(fname(val))  foo(max, [1, 2, 3])  foo(min, [1, 2, 3])

Question No# : 02 out of 20



What will be the output of the following Python code?

print("xyyzxyzxzxyy".count('yy'))

Option A. 2
Option B. 0
Option C. error
Option D. none of the mentioned
True Answer A

Explanation :
Counts the number of times the substring ‘yy’ is present in the given string.

What will be the output of the following Python code?

print("xyyzxyzxzxyy".count('yy'))

Question No# : 03 out of 20



What will be the output of the following Python code snippet?

										

Option A. 00+99
Option B. 00099
Option C. +0099
Option D. +++99
True Answer C

Explanation :
zeros are filled in between the first sign and the rest of the string.

What will be the output of the following Python code snippet?

										
									

Question No# : 04 out of 20

Which of these is not true about recursion?

Option A. Making the code look clean
Option B. A complex task can be broken into sub-problems
Option C. Recursive calls take up less memory
Option D. Sequence generation is easier than a nested iteration
True Answer C

Explanation :
Recursive calls take up a lot of memory and time as memory is taken up each time the function is called.

Which of these is not true about recursion?

Question No# : 05 out of 20



What will be the output of the following Python code?

print("xyyzxyzxzxyy".count('xyy', -10, -1))

Option A. 2
Option B. 0
Option C. 1
Option D. error
True Answer B

Explanation :
Counts the number of times the substring ‘xyy’ is present in the given string, starting from position 2 and ending at position 11.

What will be the output of the following Python code?

print("xyyzxyzxzxyy".count('xyy', -10, -1))

Question No# : 06 out of 20



What will be the output of the following Python code?

def foo(i, x=[]):      x.append(i)      return x  for i in range(3):      print(foo(i))

Option A. [0] [1] [2]
Option B. [0] [0, 1] [0, 1, 2]
Option C. [1] [2] [3]
Option D. [1] [1, 2] [1, 2, 3]
True Answer B

Explanation :
When a list is a default value, the same list will be reused.

What will be the output of the following Python code?

def foo(i, x=[]):      x.append(i)      return x  for i in range(3):      print(foo(i))

Question No# : 07 out of 20



What will be the output of the following Python code?

										

Option A. Hello foo and bin
Option B. Hello (‘foo’, ‘bin’) and (‘foo’, ‘bin’)
Option C. Error
Option D. None of the mentioned
True Answer A

Explanation :
The elements of the tuple are accessed by their indices.

What will be the output of the following Python code?

										
									

Question No# : 08 out of 20

What will be the output of the following Python code?

print("abc DEF".capitalize())

Option A. abc def
Option B. ABC DEF
Option C. Abc def
Option D. Abc Def
True Answer C

Explanation :
The first letter of the string is converted to uppercase and the others are converted to lowercase.

What will be the output of the following Python code?

print("abc DEF".capitalize())

Question No# : 09 out of 20



Which of these is not true about recursion?

Option A. It’s easier to code some real-world problems using recursion than non-recursive equivalent
Option B. Recursive functions are easy to debug
Option C. Recursive calls take up a lot of memory
Option D. Programs using recursion take longer time than their non-recursive equivalent
True Answer B

Explanation :
Recursive functions may be hard to debug as the logic behind recursion may be hard to follow.

Which of these is not true about recursion?

Question No# : 10 out of 20



What will be the output of the following Python code?

										

Option A. 0.33
Option B. 0.33%
Option C. 33.33%
Option D. 33%
True Answer C

Explanation :
The symbol % is used to represent the result of an expression as a percentage.

What will be the output of the following Python code?

										
									

Question No# : 11 out of 20

What will be the output of the following Python code?

 

def test(i,j):      if(i==0):          return j      else:          return test(i-1,i+j)  print(test(4,7))

Option A. 13
Option B. 7
Option C. Infinite loop
Option D. 17
True Answer D

Explanation :
The test(i-1,i+j) part of the function keeps calling the function until the base condition of the function is satisfied.

What will be the output of the following Python code?

 

def test(i,j):      if(i==0):          return j      else:          return test(i-1,i+j)  print(test(4,7))

Question No# : 12 out of 20



What will be the output of the following Python code?

  x=12  def f1(a,b=x):      print(a,b)  x=15  f1(4)

Option A. Error
Option B. 12 4
Option C. 4 12
Option D. 4 15
True Answer C

Explanation :
At the time of leader processing, the value of ‘x’ is 12. It is not modified later. The value passed to the function f1 is 4. Hence the output of the code shown above is 4 12.

What will be the output of the following Python code?

  x=12  def f1(a,b=x):      print(a,b)  x=15  f1(4)

Question No# : 13 out of 20



What will be the output of the following Python code?

print('*', "abcde".center(6), '*', sep='')

Option A. * abcde *
Option B. * abcde *
Option C. *abcde *
Option D. * abcde*
True Answer C

Explanation :
Padding is done towards the right-hand-side first when the final string is of even length.

What will be the output of the following Python code?

print('*', "abcde".center(6), '*', sep='')

Question No# : 14 out of 20



What will be the output of the following Python function?

complex(1+2j)

Option A. Error
Option B. 1
Option C. 2j
Option D. 1+2j
True Answer D

Explanation :
The built-in function complex() returns the argument in a complex form. Hence the output of the function shown above will be 1+2j.

What will be the output of the following Python function?

complex(1+2j)

Question No# : 15 out of 20



Which module in the python standard library parses options received from the command line?

Option A. getopt
Option B. os
Option C. getarg
Option D. main
True Answer A

Explanation :
getopt parses options received from the command line.

Which module in the python standard library parses options received from the command line?

Question No# : 16 out of 20



What will be the output of the following Python code?

  1. >>>example = "helle"
  2. >>>example.find("e")

Option A. Error
Option B. -1
Option C. 1
Option D. 0
True Answer C

Explanation :
Returns lowest index.

What will be the output of the following Python code?

  1. >>>example = "helle"
  2. >>>example.find("e")

Question No# : 17 out of 20



The small sections of code that are used to perform a particular task is called

Option A. Subroutines
Option B. Files
Option C. Pseudo code
Option D. Modules
True Answer A

Explanation :

The small sections of code that are used to perform a particular task is called

Question No# : 18 out of 20

The function divmod(a,b), where both ‘a’ and ‘b’ are integers is evaluated as:

Option A. (a%b, a//b)
Option B. (a//b, a%b)
Option C. (a//b, a*b)
Option D. (a/b, a%b)
True Answer B

Explanation :
The function divmod(a,b) is evaluated as a//b, a%b, if both ‘a’ and ‘b’ are integers.

The function divmod(a,b), where both ‘a’ and ‘b’ are integers is evaluated as:

Question No# : 19 out of 20



The variables in a function definition are called as

Option A. Subroutines
Option B. Function
Option C. Definition
Option D. Parameters
True Answer D

Explanation :

The variables in a function definition are called as

Question No# : 20 out of 20


CCC Online Test 2021 CCC Practice Test Hindi Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level NIELIT Study material and Quiz Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Website development Company in Allahabad