Which of the following changes can be made so that the code segment works as intended?

Question image

Understand the Problem

The question is asking which modification to the provided code segment will ensure that the variable 'score' is set correctly based on the values of 'score' and 'penalty', particularly avoiding negative values. This involves analyzing the logic of the code and how it handles conditions.

Answer

D (Interchanging lines 3 and 7).

The final answer is D (Interchanging lines 3 and 7).

Answer for screen readers

The final answer is D (Interchanging lines 3 and 7).

More Information

By interchanging lines 3 and 7, the code first checks if subtracting the penalty results in a negative score and handles it correctly by setting score to 0 when necessary.

Tips

A common mistake is misunderstanding the conditional logic: the penalty should only be subtracted if it doesn't lead to a negative score.

AI-generated content may contain errors. Please verify critical information

Thank you for voting!
Use Quizgecko on...
Browser
Browser