LinkedIn Python Skill Assessment Quiz Answers

What is the correct way to write a doctest?

Latest Update on 25th January, 2022 by Certification Course Answers

What is the correct way to write a doctest?

  •  A
def sum(a, b):
    """
    sum(4, 3)
    7

    sum(-4, 5)
    1
    """
    return a + b
  •  B
def sum(a, b):
    """
    >>> sum(4, 3)
    7

    >>> sum(-4, 5)
    1
    """
    return a + b
  •  C
def sum(a, b):
    """
    # >>> sum(4, 3)
    # 7

    # >>> sum(-4, 5)
    # 1
    """
    return a + b
  •  D
def sum(a, b):
    ###
    >>> sum(4, 3)
    7

    >>> sum(-4, 5)
    1
    ###
    return a + b

Correct Answer:

  •  B
def sum(a, b):
    """
    >>> sum(4, 3)
    7

    >>> sum(-4, 5)
    1
    """
    return a + b

explanation – use ''' to start the doc and add output of the cell after >>>

 

Latest Updates

No posts found in this category.