Which of the following Function Headers in Python code will result in error?

2023

Which of the following Function Headers in Python code will result in error?

Answer: D. def Compu(X, Y=10, Z=1)Answer summary: Only option D will result in an error. In Python, every function definition header must end with a colon (:). Option D is written as def…

  1. A.

    def Compu(X, Y=10, Z=100):

  2. B.

    def Compu(X, Y, Z=1):

  3. C.

    def Compu(X=100, Y=10, Z=1):

  4. D.

    def Compu(X, Y=10, Z=1)

Attempted by 1600 students.

Show answer & explanation

Correct answer: D

Answer summary: Only option D will result in an error.

In Python, every function definition header must end with a colon (:). Option D is written as def Compu(X, Y=10, Z=1) without the trailing colon, so it raises a SyntaxError.

Options A, B, and C are valid:
A. def Compu(X, Y=10, Z=100): is valid because the non-default parameter X appears before parameters with default values.
B. def Compu(X, Y, Z=1): is valid because X and Y are non-default parameters followed by the default parameter Z.
C. def Compu(X=100, Y=10, Z=1): is valid because all parameters have default values.

Therefore, the correct answer is option D.

Explore the full course: Rssb Senior Computer Instructor

Loading lesson…