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 >











No comments:

Post a Comment