Function syntax

Solve the following exercises manually. Then, use a Python shell to check your answers.

  1. The authors of the following functions claim that all of them return the double of a given value. Justify which of them are correct and which are not.

    def double_1(a):
       b = 2*a
    
    def double_2(a):
       a = 2*a
       return a
    
    def double_3(a):
       return 2*a
    
    def double_4(a):
       a = 3
       return 2*a
    
  2. Which is the result of the call f('2', 2) ? And the call f('99', '100'). And which is the type of these results ?

    def f(a, b):
       return a>b
    
  3. Which is the result of the call g(3, 2) ?

    def g(a, b):
       a = subtract(b, a)
       b = product(a, b)
       return b, a
    
    def subtract(m, n):
       return m-n
    
    def product(m, n):
       return m*n
    
  4. What does the following function return for the following calls ?: multiple(10, 2), multiple(10,3), multiple(10, 4) and multiple(10, 5).

    def multiple(num, x):
        return num%x ==0