Python Programming MCQ - Conditionals And Loops

8. Which of the following is a valid for loop in Python?

A. for(i=0; i<n; i++)
B. for i in range(0,5):
C. for i in range(0,5)
D. for i in range(5)

View Answer


9. Which of the following sequences would be generated bt the given line of code? range (5, 0, -2)

A. 5 4 3 2 1 0 -1
B. 5 4 3 2 1 0
C. 5 3 1
D. None of the above

View Answer


10. A while loop in Python is used for what type of iteration?

A. indefinite
B. discriminant
C. definite
D. indeterminate

View Answer


11. When does the else statement written after loop executes?

A. When break statment is executed in the loop
B. When loop condition becomes false
C. Else statment is always executed
D. None of the above

View Answer


12. What will be the output of the following code?

x = "abcdef"
i = "i"
while i in x:
    print(i, end=" ")

A. a b c d e f
B. abcdef
C. i i i i i ...
D. No output

View Answer


13. What will be the output of the following code?

x = 'abcd'
for i in range(len(x)):
    print(i)

A. abcd
B. 0 1 2 3
C. 1 2 3 4
D. a b c d

View Answer


14. What will be the output of the following code?

x = 12
for i in x:
    print(i)

A. 12
B. 1 2
C. Error
D. None of the above

View Answer







Also check :


Discussion


* You must be logged in to add comment.