Python Quiz Questions: MCQ!

10 Questions | Total Attempts: 889

SettingsSettingsSettings
Python Quiz Questions: MCQ! - Quiz

.


Questions and Answers
  • 1. 
    The following control structure n = 3 if n == 2:     print("Hello") elif n == 3:     print("World") else:     print("Nothing") Results is:
    • A. 

      N is assigned to 2

    • B. 

      The string "Hello" is printed to the standard out

    • C. 

      The string "World" is printed to the standard out

    • D. 

      The string "Nothing" is printed to the standard out

  • 2. 
    Which Of The Following Command Is Used To Open A File “C:\Temp.Txt” In Read-Mode Only?
    • A. 

      Infile = open(“c:\temp.txt”, “r”)

    • B. 

      Infile = open(“c:\\temp.txt”, “r”)

    • C. 

      Infile = open(file = “c:\temp.txt”, “r+”)

    • D. 

      Infile = open(file = “c:\\temp.txt”, “r+”)

  • 3. 
    Which Of The Following Command Is Used To Open A File “C:\Temp.Txt” In Append-Mode?
    • A. 

      Outfile = open(“c:/temp.txt”, “a”)

    • B. 

      Outfile = open(“c:\temp.txt”, “w+”)

    • C. 

      Outfile = open(“c:\\temp.txt”, “r+”)

    • D. 

      Outfile = open(“c:\\temp.txt”, “a”)

  • 4. 
    What is the type of a? a = {1,2:3}
    • A. 

      List

    • B. 

      Dict

    • C. 

      Set

    • D. 

      It causes SyntaxError

  • 5. 
    What is the type of b?   a = "bay"   b = a[0]
    • A. 

      Chr

    • B. 

      Ord

    • C. 

      Int

    • D. 

      Str

  • 6. 
    What is the result of this code? a=[1,2,3,4,5] a[3:1:-1]
    • A. 

      Syntax error

    • B. 

      [3, 2]

    • C. 

      [4, 3]

    • D. 

      [4, 3, 2]

  • 7. 
    What is the result of this code? a=[1,2,3,4,5,6,7,8,9] a[::2]
    • A. 

      [1,2]

    • B. 

      [1,3]

    • C. 

      Syntax error

    • D. 

      [1,3,5,7,9]

  • 8. 
    How to assign a tuple of length 1 to a?
    • A. 

      A = 1

    • B. 

      A = (1,)

    • C. 

      A = (1)

    • D. 

      A = tuple(1)

  • 9. 
    What will be placed in a? a = 2,3
    • A. 

      2

    • B. 

      3

    • C. 

      (2,3)

    • D. 

      Error

  • 10. 
    What is the output of the below program? >>> logfile = open('test.log', 'a') >>> logfile.write('line 2') >>> logfile.close() >>> print file('test.log').read()</pre>
    • A. 

      Line 2

    • B. 

      Test succeeded

    • C. 

      Open error

Related Topics
Back to Top Back to top