PCAP 31 03 PCAP Certified Associate Python Programmer · Free Practice Question Medium

Question 28

Q405 - Functions


What is the expected output of the following code?



  • A

    6

  • B

    1

  • C

    8

  • D

    3

Reveal correct answer

Correct answer: C

Explanation

Topics: def return

Try it yourself:

Explanation:

func3() gets called with 1 and returns 4

func2() gets called with 4 and returns 8

func1() gets called with 8 and returns 8


Q405 (Please refer to this number, if you want to write me about this question.)

A. This choice is incorrect because it does not consider the addition by 3 in func3 and the multiplication by 2 in func2. The final output is not 6, but 8.

B. This choice is incorrect because it does not consider the multiplication by 2 in func2 and the addition by 3 in func3. The final output is not 1, but 8.

C. The code first calls func3(1), which returns 1 + 3 = 4. Then, the result of func3(1) is passed to func2, which returns 4 * 2 = 8. Finally, the result of func2(func3(1)) is passed to func1, which simply returns the value passed to it. Therefore, the expected output is 8.

D. This choice is incorrect as it does not account for the multiplication by 2 in func2. The final output is not 3, but 8.

Discussion

Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.

You must be logged in to post a comment.

Preparing For

Your Certification?

255+ certifications
Detailed explanations
Free PDF samples

Has All The Questions You Need