Python 2 Term Quiz
Introduction to Python 2

Python Introduction to Python


Quiz : Fundemental Python 2

Part 1: Multiple Choice

  1. What is the value of the following expression?
  2. print(25/5)

    a. 5.0
    b. 5
    c. error




  3. What is the value of the following expression?
  4. print(-28//5)

    a. -5
    b. 5
    c. -6
    d. 6




  5. What is the output of the following code?
  6. def output(**args):
      for i in args:
        print(i)
    output(name = "Alice", id = 007)

    a. Alice
           007
    b. ('name', 'Alice')
            ('id', 007)
    c. name
            id
    d. TypeError




  7. What is the output of the following code?
  8. def output(*args):
      for i in args:
        print(i)
    output(name = "Alice", id = 007)

    a. Alice
           007
    b. ('name', 'Alice')
            ('id', 007)
    c. name
            id
    d. TypeError




  9. What is the output of the add() function call?
  10. def add(x, y):
      return x+3, y+5
    output = add(1, 2)
    print(output)

    a. 11
    b. 4
    c. Syntax Error
    d. (4, 7)




  11. What is the output of the following code?
  12. def first(a, b):
       def second(c, d):
         return c + d
       return second(a, b)
       return a
    res = first(10, 20)
    print(res)

    a. 10
    b. 30
    c. 30 10
    d. (30, 10)
    e. Syntax Error




  13. What is the output of the following code?
  14. myTuple = (10, 20, 30, 40, 50)
    myTuple[1] = 25
    print(myTuple)

    a. (10, 25, 30, 40, 50)
    b. (25, 20, 30, 40, 50)
    c. (10, 20, 30, 40, 50)
    d. TypeError




  15. What is the output of the following code?
  16. set1 = {10, 20, 30, 40}
    set2 = {'10', 50, '60', 70}
    set3 = set1.union(set2)
    print(set3)

    a. {40, 50, 20, 30, 10, 60, 70}
    b. {40, 50, 20, 30, 10, 60, '10', 70}
    c. {40, 50, 20, 30, '10', 60, 70}
    d. SyntaxError




  17. What is the output of the following code?
  18. shapeSet = {'triangle','circle','hexagon','pantagon'}
    print(shapeSet[1])

    a. circle
    b. triangle
    c. 'circle'
    d. SyntaxError




  19. Which is true for Python function?
  20. a. A function can return only a single value
    b. A function can take an unlimited number of arguments
    c. A function can return multiple values
    d. A function doesn't return anythin unless add a return statement
    e. A function is a code block that only executes when it is called
    f. A function always returns a value
    g. A function can be reused in a program
    h. Python doesn't support nested function




  21. Which is true for Python tuple?
  22. a. A tuple maintains the order of items
    b. A tuple is unordered
    c. We cannot change the tuple once created
    d. We cannot remove items from the tuple
    e. We cannot delete the tuple
    f. We cannot update items of the tuple
    g. A tuple can be created without using parentheses




  23. Which is true for Python set?
  24. a. Set is unordered
    b. Set does not allow duplicate
    c. Set is around by curly braces
    d. Set is immutable
    e. Set supports indexing




Part 2: Complete input field

  1. What is the output of the following function call?
  2. def first(a, b):
       def second(c, d):
         return c + d
       return second(a, b)
    res = first(10, 20)
    print(res)





  3. What is the output of the code?
  4. x = [1,2]
    y = x
    y += [3,4]
    print(x, end=' ')
    print(y)



  5. What is the output of the following code?
  6. myTuple = (10, 20, 30, 40, 50)
    print(myTuple[-2])



    print(myTuple[-4:-1])



    numTuple = (0, 10, 20, 30, 40, 50, 60, 70, 80)
    print(numTuple[2:5], numTuple[:4], numTuple[3:])



Part 3: Coding

Narcissistic Number

  • What is Narcissistic Number?
  • Click here to learn more about Narcissistic Number!
  • A Narcissistic Number is a number that is the sum of its own digits each raised to the power of the number of digits.
  • How to determine if a number is a Narcissistic Number?
  • (Optional) Can you print all Narcissistic Number in the range of 1 to 999?


Part 4: File I/O

Alice's Adventures in Wonderland

  • Click here to download the text file to your local computer.
  • Write a program to count how many times the "March Hare" appears.
  • Generate a custom WordCloud image.