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 >











No comments:

Post a Comment