# Peer Instruction: Functions Multiple Choice Questions¶

- Raaarrr I’m a bear
- Correct! The function "foo()" has been called in the last line. So, the print statement under it will be executed.
- Eeek a bear!
- Incorrect! The function "foo()" has been called in the last line and NOT "bar()". So, the print statement under "foo()" will be executed and returned.
- Both
- Incorrect! The function "foo()" has been called in the last line and NOT "bar()". So, the print statement under "foo()" will be executed and returned.
- Neither
- Incorrect! The function "foo()" has been called in the last line and NOT "bar()". So, the print statement under "foo()" will be executed and returned.
- I don’t know

Q-1: This code will print:

```
def foo():
print(“Raaarrr I’m a bear”)
def bar():
print(“Eeek a bear!”)
foo()
```

- 0
- Incorrect! Change in the values of a function's arguments doesn't change the assigned value of a variable. Try replacing "first(a)" with "first(x)" in function definition.
- 8
- Incorrect! Change in the values of a function's arguments doesn't change the assigned value of a variable. Try replacing "first(a)" with "first(x)" in function definition.
- 20
- Correct! Change in the values of a function's arguments doesn't change the assigned value of a variable.
- Error, because a cannot be assigned in two places
- Incorrect! Change in the value of a function's arguments doesn't change the assigned value of a variable. Try replacing "first(a)" with "first(x)" in function definition.
- I don’t know
- Incorrect! Change in the values of a function's arguments doesn't change the assigned value of a variable. Try replacing "first(a)" with "first(x)" in function definition.

Q-2: What will the output be?

```
def first(a):
a=8
a = 20
first(a)
print(a)
```

- 5
- Incorrect! Here, a=x=2 and b= 3+1 = 4. So, a + b + 3 = 2 + 4 + 3 = 9.
- 9
- Correct! Here, a=x=2 and b= 3+1 = 4. So, a + b + 3 = 2 + 4 + 3 = 9.
- 0
- Incorrect! Here, a=x=2 and b= 3+1 = 4. So, a + b + 3 = 2 + 4 + 3 = 9.
- 3
- Incorrect! Here, a=x=2 and b= 3+1 = 4. So, a + b + 3 = 2 + 4 + 3 = 9.
- I don't know
- Incorrect! Here, a=x=2 and b= 3+1 = 4. So, a + b + 3 = 2 + 4 + 3 = 9.

Q-3: What will the output be?

```
def calculate(w, x, y):
a=x
b=w+1
return a + b + 3
print(calculate(3, 2, 0))
```

- x = f1()
- Correct! Only function "f1()" has a return statement.
- x = f2()
- Incorrect! Only function "f1()" has a return statement.
- x = f3()
- Incorrect! Only function "f1()" has a return statement.
- All of the above
- Incorrect! Only function "f1()" has a return statement.
- I don't know
- Incorrect! Only function "f1()" has a return statement.

Q-4: Which assigns x to 5?

```
def f1():
return 5
def f2():
print(5)
def f3():
return print(5)
```

- No bugs. The code is fine.
- Incorrect! Body of the function is not indented.
- The function body is not indented.
- Correct! Function body should be indented in Python.
- We use x as both a parameter and a variable, but we are not allowed to do that
- Incorrect! x can be defined as both a parameter and variable in Python.
- B and C
- Incorrect! Function body should be indented in Python. x can be defined as both a parameter and variable in Python.
- I don't know
- Incorrect! Body of the function is not indented.

Q-5: What are the bugs in the following code?

```
def add_one(x):
return x + 1
x = 2
x = x + add_one(x)
```

- 8, 8
- Incorrect! Here, odd(4, 2) will return 15 (y = y + 1 = 5 and x = x + 1 = 3) and print(x*y) in main() will return 8. The output of odd() will be printed first as it is initialized first.
- 15, 15
- Incorrect! Here, odd(4, 2) will return 15 (y = y + 1 = 5 and x = x + 1 = 3) and print(x*y) in main() will return 8. The output of odd() will be printed first as it is initialized first.
- 8, 15
- Incorrect! Here, odd(4, 2) will return 15 (y = y + 1 = 5 and x = x + 1 = 3) and print(x*y) in main() will return 8. The output of odd() will be printed first as it is initialized first.
- 15, 8
- Correct! Here, odd(4, 2) will return 15 (y = y + 1 = 5 and x = x + 1 = 3) and print(x*y) in main() will return 8. The output of odd() will be printed first as it is initialized first.
- I don't know

Q-6: What will the output be?

```
def odd(y,x):
y = y +1
x = x + 1
print(x*y)
def main():
x = 2
y = 4
odd(x,y)
print(x*y)
```

You have attempted of activities on this page