Python Programming Quiz – 10th Week Quiz Solution

13
2165
Python Programming Quiz – 10th Week Quiz Solution
Python Programming Quiz – 10th Week Quiz Solution

Disclaimer for ReGyan

If you require any more information or you have any problem regarding Copyright or have any questions about our site’s disclaimer, please feel free to contact us by email at hello@regyan.com.

Disclaimers for ReGyan

All the information on this website is published in good faith and for general information and educational purpose only. ReGyan does not make any warranties about the completeness, reliability, and accuracy of this information. Any action you take upon the information you find on this website (regyan.com), is strictly at your own risk. will not be liable for any losses and/or damages in connection with the use of our website.

 


Python Programming Quiz – 10th Week Quiz Solution given in this post.

[1] What kind of exception will be raised by (using python 3.X version):

assert 5>10
  • (a): ValueError exception
  • (b): AssertionError exception
  • (c): ZeroDivisionError exception
  • (d): No exception is raised by the program

Answer: (b) AssertionError exception

[2] What kind of exception will be raised by (using python 3.X version):

assert 5/0 > 0
  • (a): ValueError exception
  • (b): AssertionError exception
  • (c): ZeroDivisionError exception
  • (d): No exception is raised by the program

Answer:(c) ZeroDivisionError exception

[3] What kind of exception will be raised by (using python 3.X version)

assert 10/5 > 0
  • (a): ValueError exception
  • (b): AssertionError exception
  • (c): ZeroDivisionError exception
  • (d): No exception is raised by the program

Answer:(d) No exception is raised by the program

[4] For the following Pyhton3 program

assert len(item) < 5
An assertion is NOT generated if the value of item is (using python 3.X version):
  • (a): [1, 2, 3, 4, 5, 6]
  • (b): range(0, 3)
  • (c): No Assertion Error
  • (d): (51,52,53,54,55)

Answer: (b) range(0, 3)

[5] Can the assert statements in a program be disabled by passing -O option to the python interpreter.

  • (a): True
  • (b):  False




Answer: (a) True

[6] Which of the following data structures in python can be traversed using for…in statement –

  • (a): tuple
  • (b): string
  • (c): dictionary
  • (d): all of the above

Answer: (d) all of the above

Also, see: Python Programming Quiz – 9th Week Quiz Solution

[7] In python, for loop terminates when next() raises StopIteration exception.

  • (a): True
  • (b): False

Answer: (a) True

[8] While we create our own iterator, if the class defines __next__(), then __iter__() can just return self.

  • (a): True
  • (b): False

Answer: (a) True

[9] Which of the following mathematical function definitions is recursive –

(a) factorial(0) = 1
  factorial(n) = n*factorial(n-1) where n>=0
(b) f(0) = 0
  	f(1) = 1
  	f(n) = f(n-1) + f(n-2) where n>=0
(c) both (a) and (b)
(d) none of (a) and (b)
  • (a): a
  • (b): b
  • (c): c
  • (d): d

Also See:- TCS Recruitment 2020 Apply Online Form

Answer: (c)  c

[10] A function not calling itself (directly/indirectly) is called a recursive functio

  • (a): True
  • (b): False

Answer: (b) false




[11] Which of following is not a property of properly defined recursive functions –

  • (a): change of argument between recursive calls 
  • (b): change of arguments is towards base case
  • (c): there must be zero or more base cases
  • (d): none of the above

Answer: (c) there must be zero or more base cases

[12] Estimating the time taken by a program requires to consider only function calls as operations.

  • (a): True
  • (b): False

Answer: (b) False

[13] Time taken by a function call is proportional to the number of simple operations performed by the call before returning.

  • (a): True
  • (b): False

Answer: (a) True

[14]  Solution to the recurrence relation T(n) = T(n-1) + 1 where T(1) = 1 is –

  • (a): T(n) = n-2
  • (b): T(n) = n-1
  • (c): T(n) = n
  • (d): T(n) = n+1




Answer: (c) T(n) = n

[15] Solution to the recurrence relation T(n) = T(n-1) + n where T(1) = 1 is –

  • (a): T(n) = n*(n-1)/2
  • (b): T(n) = n*(n+1)/2
  • (c): T(n) = n*n
  • (d): None of the above

Answer: (b) T(n) = n*(n+1)/2

That’s all for the  Python programming Quiz – 10th Week Quiz Solution. if you have any questions, please comment down below, we will try to answer within the first 24 hours. I hope you liked this content. We will come to another week’s quiz. Thanks for reading.

13 COMMENTS

LEAVE A REPLY

Please enter your comment!
Please enter your name here