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

FUNCTIONS IN PYTHON

00:00:00

Suppose there is a list such that: l=[2,3,4]. If we want to print this list in reverse order, which of the following methods should be used?

Option A. reverse(l)
Option B. list(reverse[(l)])
Option C. reversed(l)
Option D. list(reversed(l))
True Answer D

Explanation :
The built-in function reversed() can be used to reverse the elements of a list. This function accepts only an iterable as an argument. To print the output in the form of a list, we use: list(reversed(l)). The output will be: [4,3,2].

Suppose there is a list such that: l=[2,3,4]. If we want to print this list in reverse order, which of the following methods should be used?

Question No# : 01 out of 20



What will be the output of the following Python function?

min(max(False,-3,-4), 2,7)

Option A. 2
Option B. False
Option C. -3
Option D. -4
True Answer B

Explanation :
The function max() is being used to find the maximum value from among -3, -4 and false. Since false amounts to the value zero, hence we are left with min(0, 2, 7) Hence the output is 0 (false).

What will be the output of the following Python function?

min(max(False,-3,-4), 2,7)

Question No# : 02 out of 20



What will be the output of the following Python code?

print("ccdcddcd".find("c"))

Option A. 4
Option B. 0
Option C. Error
Option D. True
True Answer B

Explanation :
The first position in the given string at which the substring can be found is returned.

What will be the output of the following Python code?

print("ccdcddcd".find("c"))

Question No# : 03 out of 20



What will be the output of the following Python code?

print("Hello {0} and {1}".format(('foo', 'bin')))

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 C

Explanation :
IndexError, the tuple index is out of range.

What will be the output of the following Python code?

print("Hello {0} and {1}".format(('foo', 'bin')))

Question No# : 04 out of 20



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

										

Option A. 000ab
Option B. 00ab0
Option C. 0ab00
Option D. ab000
True Answer A

Explanation :
The string is padded with zeros on the left hand side. It is useful for formatting numbers.

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

										
									

Question No# : 05 out of 20

What is the return type of function id?

Option A. int
Option B. float
Option C. bool
Option D. dict
True Answer A

Explanation :
Execute help(id) to find out details in python shell.id returns a integer value that is unique.

What is the return type of function id?

Question No# : 06 out of 20



What will be the output of the following Python code?

print("Hello {name1} and {name2}".format('foo', 'bin'))

Option A. Hello foo and bin
Option B. Hello {name1} and {name2}
Option C. Error
Option D. Hello and
True Answer C

Explanation :
The arguments passed to the function format aren’t keyword arguments.

What will be the output of the following Python code?

print("Hello {name1} and {name2}".format('foo', 'bin'))

Question No# : 07 out of 20



Which of the following is a distinct syntactic block?

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

Explanation :

Which of the following is a distinct syntactic block?

Question No# : 08 out of 20

What will be the output of the following Python function?

float(' -12345\n')

Option A.   -12345.0 (5 blank spaces before the number)
Option B. -12345.0
Option C. Error
Option D. -12345.000000000…. (infinite decimal places)
True Answer B

Explanation :
The function float() will remove all the blank spaces and convert the integer to a floating point number. Hence the output will be: -12345.0.

What will be the output of the following Python function?

float(' -12345\n')

Question No# : 09 out of 20



What will be the output of the following Python code?

print("xyyzxyzxzxyy".endswith("xyy", 0, 2))

Option A. 0
Option B. 1
Option C. True
Option D. False
True Answer D

Explanation :
The function returns False if the given string does not end with the specified substring.

What will be the output of the following Python code?

print("xyyzxyzxzxyy".endswith("xyy", 0, 2))

Question No# : 10 out of 20



What is the output of the function complex()?

Option A. 0j
Option B. 0+0j
Option C. 0
Option D. Error
True Answer A

Explanation :
The complex function returns 0j if both of the arguments are omitted, that is, if the function is in the form of complex() or complex(0), then the output will be 0j.

What is the output of the function complex()?

Question No# : 11 out of 20



What happens if a local variable exists with the same name as the global variable you want to access?

Option A. Error
Option B. The local variable is shadowed
Option C. Undefined behavior
Option D. The global variable is shadowed
True Answer D

Explanation :
If a local variable exists with the same name as the local variable that you want to access, then the global variable is shadowed. That is, preference is given to the local variable.

What happens if a local variable exists with the same name as the global variable you want to access?

Question No# : 12 out of 20



Observe the following Python code?

def a(n):      if n == 0:          return 0      else:          return n*a(n - 1)  def b(n, tot):      if n == 0:          return tot      else:          return b(n-2, tot-2)

Option A. Both a() and b() aren’t tail recursive
Option B. Both a() and b() are tail recursive
Option C. b() is tail recursive but a() isn’t
Option D. a() is tail recursive but b() isn’t
True Answer C

Explanation :
A recursive function is tail recursive when recursive call is executed by the function in the last.

Observe the following Python code?

def a(n):      if n == 0:          return 0      else:          return n*a(n - 1)  def b(n, tot):      if n == 0:          return tot      else:          return b(n-2, tot-2)

Question No# : 13 out of 20



What will be the output of the following Python code?

def f1(x):      global x      x+=1      print(x)  f1(15)  print("hello")

Option A. error
Option B. hello
Option C. 16
Option D. 16 hello
True Answer A

Explanation :
The code shown above will result in an error because ‘x’ is a global variable. Had it been a local variable, the output would be: 16 hello

What will be the output of the following Python code?

def f1(x):      global x      x+=1      print(x)  f1(15)  print("hello")

Question No# : 14 out of 20



What is tail recursion?

Option A. A recursive function that has two base cases
Option B. A function where the recursive functions leads to an infinite loop
Option C. A recursive function where the function doesn’t return anything and just prints the values
Option D. A function where the recursive call is the last thing executed by the function
True Answer D

Explanation :
A recursive function is tail recursive when recursive call is executed by the function in the last.

What is tail recursion?

Question No# : 15 out of 20



Which of the following statements is false about recursion?

Option A. Every recursive function must have a base case
Option B. Infinite recursion can occur if the base case isn’t properly mentioned
Option C. A recursive function makes the code easier to understand
Option D. Every recursive function must have a return value
True Answer D

Explanation :
A recursive function needn’t have a return value.

Which of the following statements is false about recursion?

Question No# : 16 out of 20



How are default arguments specified in the function heading?

Option A. identifier followed by an equal to sign and the default value
Option B. identifier followed by the default value within backticks (“)
Option C. identifier followed by the default value within square brackets ([])
Option D. identifier
True Answer A

Explanation :
Refer documentation.

How are default arguments specified in the function heading?

Question No# : 17 out of 20



What will be the output of the following Python code?

print("abcdef".center(7, '1'))

Option A. 1abcdef
Option B. abcdef1
Option C. abcdef
Option D. error
True Answer A

Explanation :
The character ‘1’ is used for padding instead of a space.

What will be the output of the following Python code?

print("abcdef".center(7, '1'))

Question No# : 18 out of 20



What will be the output of the following Python code?

def f1():      global x      x+=1      print(x)  x=12  print("x")

Option A. Error
Option B. 13
Option C. 13 x
Option D. x
True Answer D

Explanation :
In the code shown above, the variable ‘x’ is declared as global within the function. Hence the output is ‘x’. Had the variable ‘x’ been a local variable, the output would have been: 13 x

What will be the output of the following Python code?

def f1():      global x      x+=1      print(x)  x=12  print("x")

Question No# : 19 out of 20



What will be the output of the following Python code?

def foo(k):      k[0] = 1  q = [0]  foo(q)  print(q)

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

Explanation :
Lists are passed by reference.

What will be the output of the following Python code?

def foo(k):      k[0] = 1  q = [0]  foo(q)  print(q)

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