MCQ Quiz: Python Programming!

10 Questions | Total Attempts: 134

SettingsSettingsSettings
Please wait...
MCQ Quiz: Python Programming!

.


Questions and Answers
  • 1. 
    How to change global variables locally?
    • A. 

      Use global <variable name> in the function

    • B. 

      Use local <variable name> in the function

    • C. 

      Use global <variable name> outside the function

    • D. 

      None of the above

  • 2. 
    What will be printed: >>> def f(a, b):              print(a, b) >>> f(b=1, *(2,))
    • A. 

      Error

    • B. 

      1 1

    • C. 

      2 1

    • D. 

      1 2

  • 3. 
    Below syntax is correct or not? def f(a):     pass f(a for a in [1,2])  
    • A. 

      Yes

    • B. 

      No

  • 4. 
    What does this function return? >>> def f(a,b):             return a,b >>> f(**{'b':2,'a':1})
    • A. 

      Error

    • B. 

      1,1

    • C. 

      2,1

    • D. 

      1,2

  • 5. 
    Import random print random.randint(0, 5) This will output either 0,1, 2, 3, 4 or 5.
    • A. 

      TRUE

    • B. 

      FALSE

  • 6. 
    What is the output of this program? >>>colors = ["blue", "lavender", "red", "yellow"] >>>for color in sorted(colors, key=lambda color: len(color), reverse=True):       print(color)
    • A. 

      Lavender yellow blue Red

    • B. 

      Yellow blue Red

    • C. 

      Yellow blue Red lavender

    • D. 

      None of the above

  • 7. 
    What is the output of this program? >>>furniture = {"table" : 1, "chair" : 2, "desk" : 4} >>>s = sorted(furniture.keys()) >>>for key in s:         print(key, furniture[key])
    • A. 

      Chair 2 desk 4 table 1

    • B. 

      Error

    • C. 

      "chair 2" "desk 4" "table 1"

    • D. 

      None of the above

  • 8. 
    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

  • 9. 
    When will the else part of try-except-else be executed?
    • A. 

      Always

    • B. 

      When an exception occurs

    • C. 

      When no exception occurs

    • D. 

      When an exception occurs in to except block

  • 10. 
    Is the following Python code valid? try: # Do something except: # Do something finally: # Do something
    • A. 

       no, there is no such thing as finally

    • B. 

      No, finally cannot be used with except

    • C. 

      No, finally must come before except

    • D. 

      Yes

Related Topics
Back to Top Back to top