Saturday 14 March 2020

MCQs Python while loop Set 1

MCQs based on Python while loop




Question 1. What will be the output of following python while loop code?
num = 1
while num < 5:
  print(num, end=" ")
  num = num + 1

A. 1 2 3 4
B. 1 2 3 4 5
C. 1 3 5
D. none of these

Question 2. What is the output of following python while loop code?
    num = 1
    while num < 5:
      print(num, end=" ")
      if num == 2:
        break
      num += 1
A. 1 3 4
B. 1 2
C. 1 2 3 4 5
D. none of these

Question 3. What is the output of following python while loop code?

    num = 1
    while num < 5:
      num += 1
      if num == 2:
        continue
      print(num, end=" ")
A. 1 2 3 4
B. 1 2
C. 3 4 5
D. Syntax error

Question 4. Predict output of the following python while code.

    num = 1
    while num < 5:
        print(num, end=" ")
        num = num + 1
    else:
        print("'num' is now out of range.")
A. 1 2 3 4 'num' is now out of range.
B. 1 2 3 4
C. 'num' is now out of range.
D. none of these

Question 5. Predict output of the following python while code.

    flag = 1

    while flag == 1:
        print(flag + 1)

    print("1 2 3 4 5")
A. infinite loop
B. 1 2 3 4 5
C. 2 3 4 5
D. Syntax error


   


Score out of 5 =  

Percentage =


Back to Python MCQs >











Friday 13 March 2020

Python for loop MCQs Set 1

MCQs based on Python for loop



Question 1. Predict output of following python code:


    str = 'pythonpracticals'
    for i in str:
        print(i.upper(), end="")
A. PYTHONPRACTICALS
B. python
C. pythonpracticals
D. none of these

Question 2. What is the output of the following python code?

    str = 'pythonpracticals'
    for i in str[0:6]:
        print(i, end="")
A. pythonpracticals
B. python
C. practicals
D. error

Question 3. What is the output of the following?

    number = 5
    sum=0
    for i in range (1,5):
        sum=sum+i
    print(sum)
A. 1
B. 5
C. 10
D. error

Question 4. Predict output of following python code:

    dict1 = {0: 'a', 1: 'b', 2: 'c', 3:'d'}
    for i in dict1.values():
        print(i, end="") 
A. abcd
B. 0123
C. 0a1b2c3d
D. error

Question 5. Predict output of following python code:

    print("Hello")
    for i in range(5, 1):
       print (i)
A. Hello5 4 3 2 1
B. Hello1 2 3 4 5
C. Hello5 4 3 2
D. Hello


   


Score out of 5 =  

Percentage =


Back to Python MCQs >











Thursday 12 March 2020

MCQs based on Python if else set 1

MCQs based on Python if else




Question 1. If the Boolean expression of if statement evaluates to ________, then the block of code inside the if statement will be ignored.
A. True
B. False
C. both True and False
D. none of these

Question 2. Predict output of the following python program.
a, b, c = 5, 1, 15

if (a < b) and (a < c):
  print("A is minimum")
elif (b < a) and (b < c):
  print("B is minimum")
else:
  print("C is minimum")
A. A is minimum
B. B is minimum
C. C is minimum
D. none of these

Question 3. Predict output of following python code:
if(4-6):
   print("Android")
else:
   print("Linux")


A. Android
B. Linux
C. Error
D. none of these

Question 4. What will be the output of the following python program?

    if False:
       print ("AAA")
    elif True:
       print ("BBB")
    else:
       print ("CCC")

A. AAA
B. BBB
C. CCC
D. none of these

Question 5. What will be the output of the following python program?


    result = 50
    if(result != 50):
       flag=0
    else:
       flag=1
    if(flag==0):
       print("Pass")
    else:
       print("Fail")

A. Pass
B. Fail
C. Syntax Error
D. none of these



Score out of 5 =

Score in percentage =

Check Your Answer Here






Tuesday 10 March 2020

MCQs based on Python Basics - Set 1

MCQs based on Python Basics - Set 1




Question 1. The _______ are names given to some data or information that we want to store in a Python programs.
A. variables
B. tokens
C. keywords
D. none of these

Question 2. Which of the following character can be used to specify comments in Python?
A. #
B. $
C. //
D. none of these

Question 3. The _______are used to describe the code and are not interpreted by Python.
A. variables
B. comments
C. tokens
D. loops

Question 4. A variable name cannot start with a __________.
A. number
B. letter
C. underscore
D. none of these

Question 5. Which of the following is invalid identifier name?
A. _num
B. Num
C. 101_
D. Syntax


   


Score out of 5 =  

Percentage =

Check Your Answer Here

Back to Python MCQs >