Functions
Functions
x, y = f(5)
print(x + y)
2. True or False: Names that are valid for variables are also valid for functions.
3. What output is produced by the print() statement when the following code is executed?
def calc_q1(x):
q=4*x+1
return q
calc_q1(5)
print(q)
(a) 24
(b) 21
(c) q
(d) This produces an error.
(e) None of the above.
4. What is the value of q after the following code has been executed?
def calc_q2(x):
q=4*x+1
print(q)
q = calc_q2(5)
(a) 24
(b) 21
(c) This produces an error.
(d) None of the above.
5. What is the value of q after the following code has been executed?
q = 20
def calc_q3(x):
q=4*x+1
return q
q = calc_q3(5)
(a) 24
(b) 21
(c) This produces an error.
(d) None of the above.
6. What is the output produced by the print() statement in the following code?
def calc_q4(x):
q=4*x+1
print(calc_q4(5))
(a) 24
(b) 21
(c) q
(d) This produces an error.
(e) None of the above.
def main():
get_input()
print(x ** 2)
main()
At the prompt the user enters 2. What is the output of this program?
(a) x ** 2
(b) 4
(c) 4.0
(d) This produces an error.
(e) None of the above.
10. The following code is executed:
def get_input():
x = float(input("Enter a number: "))
return x
def main():
print(get_input() ** 2)
main()
At the prompt the user enters 2. What is the output of this program?
(a) get_input() ** 2
(b) 4
(c) 4.0
(d) This produces an error.
(e) None of the above.
z = f1(3, 3) + 1
(a) 3
(b) 3.0
(c) 2
(d) This produces an error.
z = f2(3, 3) + 1
(a) 3
(b) 3.0
(c) 2
(d) This produces an error.
(e) None of the above.
z = f3(3, 3) + 1
(a) 3
(b) 3.0
(c) 2
(d) This produces an error.
(e) None of the above.
14. What is the value of z after the following code is executed?
def f3(x, y = 2):
return (x + 1) / (y - 1)
z = f3(3) + 1
(a) 3
(b) 3.0
(c) 2
(d) This produces an error.
(e) None of the above.
x = 10
inc_by_two(x)
print("x = ", x)
X = 10