Python Online Quiz


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 output for −

raining'. find('z') ?

A - Type error

B - ' '

C - -1

D - Not found

Answer : C

Explanation

If the string is not found by method find() , it returns the integer -1.

Q 2 - Which of the following is false statement in python

A - int(144)==144

B - int('144')==144

C - int(144.0)==144

D - None of the above

Answer : D

Explanation

The built-in int() type constructor converts string and floating value to integer.

Q 3 - How can we generate random numbers in python using methods?

A - random.uniform ()

B - random.randint()

C - random.random()

D - All of the above

Answer : D

Explanation

To generate random numbers we import random module and in that module we have these methods/functions.

uniform(x,y) returns a floating number in the range [x,y] random() returns a floating point number in the range [0, 1].

randint(x,y) returns a random integer number in the range [x, y].

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?

def nprint(message, n):
while(n > 0):
   print(message)
n-=1
nprint('z', 5)

A - zzzz

B - zzzzz

C - Syntax Error

D - Infinite Loop

Answer : D

Explanation

Because decrementing condition of ‘n’ is not present in the while loop.

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

eval(''1 + 3 * 2'')

A - ‘1+6’

B - ‘4*2’

C - ‘1+3*2’

D - 7

Answer : D

Explanation

Eval is a method used to evaluate the values entered in the braces.

Q 7 - Which of the function among will return 4 on the set s = {3, 4, 1, 2}?

A - Sum(s)

B - Len(s)

C - Max(s)

D - Four(s)

Answer : B & C.

Explanation

len(s) returns the length of the set and max(s) returns the maximum value in the set.

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.

Answer : B

Explanation

Text is created in the canvas by using create_text method of canvas. Color of the text can be set according to the user which is specified under ‘filled’.

Q 10 - Best part is you can display images in various options in Python. Select the option where you can display an image −

A - Only A label

B - Only A button and A label

C - Only A checkbox

D - A label, a check box , a button and a radio button.

Answer : D

python_questions_answers.htm
Advertisements