4.3.3.Graded Quiz Functions - sj50179/IBM-Data-Science-Professional-Certificate GitHub Wiki

LATEST SUBMISSION GRADE

100%

Question 1

Consider the function step, when will the function return a value of 1?

def step(x):
    if x>0:
        y=1
    else:
        y=0
    return y
  • if x is larger than 0

  • if x is equal to or less then zero

  • if x is less than zero

Correct, the value of y is 1 only if x is larger than 0

Question 2

Given the function add shown below, what does the following return?

def add(x):
    return(x+x)
    
add('1')

  • 2

  • '11'

  • '2'

correct, the input is not an integer

Question 3

What is the correct way to sort list 'B' using a method? The result should not return a new list, just change the list 'B'.

  • B.sort()

  • sort(B)

  • sorted(B)

  • B.sorted()

Correct

Question 4

What is the output of the following lines of code?

a=1

def do(x):
    a=100
    return(x+a)

print(do(1))

  • 2

  • 101

  • 102

Correct, the value of a=100 exists in the local scope of the function. Therefore the value of a=1 in the global scope is not used.

Question 5

Write a function name add that takes two parameter a and b, then return the output of a + b (Do not use any other variable! You do not need to run it. Only write the code about how you define it.)

def add(a,b):
    return(a + b)

Correct. Good job!