nerdexam
Python_Institute

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

The function body is missing. What snippet would you insert in the line indicated below:
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)
  • A
    15% (8)
  • B
    8% (4)
  • C
    2% (1)
  • D
    75% (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 print 7 from inside the function, then print(func(7)) would still print None - you'd see two lines of output and the outer print call would be useless.
  • B (return 'number') returns the string literal "number", not the variable number, so func(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.

Full PCEP-30-02 Practice