PCEP-30-02 · Question #163
The function body is missing. What snippet would you insert in the line indicated below: ``python 1 def func(number): 2 # insert your code here 3 4 print(func(7)) ``
The correct answer is D. return number. Option D (return number) is correct because the function is called inside print(func(7)), meaning func must return a value for print to display it - without a return statement, the function returns None, and print(None) would output None. A and C (print(number)) would print 7…
Question
1 def func(number):
2 # insert your code here
3
4 print(func(7))
Options
- Aprint(number)
- Breturn 'number'
- Cprint(number)
- Dreturn number
How the community answered
(53 responses)- A15% (8)
- B8% (4)
- C2% (1)
- D75% (40)
Explanation
Option D (return number) is correct because the function is called inside print(func(7)), meaning func must return a value for print to display it - without a return statement, the function returns None, and print(None) would output None.
- A and C (
print(number)) would print7from inside the function, thenprint(func(7))would still printNone- you'd see two lines of output and the outerprintcall would be useless. - B (
return 'number') returns the string literal"number", not the variablenumber, sofunc(7)would always output"number"regardless of the argument passed.
Memory tip: Whenever you see a function call nested inside print(func(...)), the function itself must return - not print - because the outer print is what handles the display.
Community Discussion
No community discussion yet for this question.