Python Online Quiz


Advertisements


Following quiz provides Multiple Choice Questions (MCQs) related to Python. You will have to read all the given answers and click over the correct answer. If you are not sure about the answer then you can check the answer using Show Answer button. You can use Next Quiz button to check new set of questions in the quiz.

Questions and Answers

Q 1 - What is the output for −

S = [['him', 'sell'], [90, 28, 43]]

S[0][1][1]

A - 'e'

B - 'i'

C - '90'

D - 'h'

Answer : A

Explanation

List can contain other list values.

So, in this question S[0] gives ['him', 'sell'], S[0][1] gives ‘sell’ and S[0][1][1] gives ‘e’.

Remember, the index in python starts with ‘0’.

Q 2 - What is output for −

b = [11,13,15,17,19,21]

ptint(b[::2])

A - [19,21]

B - [11,15]

C - [11,15,19]

D - [13,17,21]

Answer : C

Explanation

b[::2] :- it iterates over the list with ‘2’ increments

Q 3 - Name the error that doesn’t cause program to stop/end, but the output is not the desired result or is incorrect.

A - Syntax error

B - Runtime error

C - Logical error

D - All of the above

Answer : C

Explanation

logical error doesn’t cause the program to stop/end, but the output is not the desired result or is incorrect.

Q 4 - What is output of following code −

def func(n):
   if(n==1):
      return 1;
   else:
      return(n+func(n-1))
print(func(4))

A - 12

B - 10

C - 9

D - 11

Answer : B

Q 5 - What is the output of the following code?

import math
 
   def main():
      math.cos(math.pi)
main()
   print(main())

A - -1

B - None

C - Error

D - Math.pi not defined

Answer : B

Explanation

None is printed because function does not return the value.

Q 6 - Guess the output −

def main(): 
   try: 
      func() 
      print(''print this after function call'') 
   except ZeroDivisionError: 
      print('Divided By Zero! Not Possible! ') 
   except: 
      print('Its an Exception!') 
def func(): 
   print(1/0) 
main()

A - ‘Its an Exception!’

B - ‘Divided By Zero! Not possible!’

C - ‘print this after function call’ followed by ‘Divided By Zero! Not Possible!’

D - ‘print this after function call’ followed by ‘Its an Exception!’

Answer : B

Explanation

The function ‘func’ will not run because it contains an exception. So in try and expect block. The function called under try will not run and will move to except block which defines the type of exception present in the function ‘func’. Thus block of statements present in except ZeroDivisionError is printed.

Q 7 - Analyze the code −

print(''Recursive Function'') 
def factorial(n): 
   return(n*factorial(n-1))  
factorial(4)

A - Recursive Function 24.

B - Recursive Function.

C - Function runs infinitely and causes a StackOverflowError.

D - Syntax Error.

Answer : C

Explanation

there is no condition in the code to stop the function.

Answer : C

Explanation

For the type of message user want to display on the window of python there is a type of code according to it. Example for warning message user choose showwarning method.

Q 9 - Which way among them is used to create an event loop ?

A - Window.eventloop()

B - Window.mainloop()

C - Window.loop()

D - Eventloop.window()

Answer : B

Q 10 - How you can lift the pen of in turtle?

A - Turtle.lift()

B - Turtle.liftup()

C - Turtle.penup()

D - Turtle.up()

Answer : C


python_questions_answers.htm

Advertisements