Skip to content

Commit

Permalink
Fix buggy feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
bhoffman0 committed Nov 14, 2024
1 parent 646fa6f commit bdf70af
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions _sources/Unit4-Iteration/topic-4-5-loop-analysis.rst
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@ Did your trace table look like the following?
:answer_d: var1 = 0, var2 = 2
:answer_e: The loop will cause a run-time error with a division by zero
:correct: b
:feedback_a: The loop stops one of two ways, when var2 = 0 or when var1 / var2 = 0 - neither is true in this case
:feedback_a: The loop stops one of two ways, when var2 = 0 or when var1 / var2 < 0 - neither is true in this case
:feedback_b: The loop stopped because var2 = 0. After the first execution of the loop var1 = 1 and var2 = 1. After the second execution of the loop var1 = 2 and var2 = 0. This stops the loop and doesn't execute the second part of the complex conditional.
:feedback_c: The loop stops one of two ways, when var2 = 0 or when var1 / var2 = 0 - neither is true in this case
:feedback_d: The loop stops one of two ways, when var2 = 0 or when var1 / var2 = 0 - neither is true in this case
:feedback_e: Even though var1 = 2 and var2 = 0 when the conditional is executed the first condition is true so the rest of the complex conditional won't execute.
:feedback_c: The loop stops one of two ways, when var2 = 0 or when var1 / var2 < 0 - neither is true in this case
:feedback_d: The loop stops one of two ways, when var2 = 0 or when var1 / var2 < 0 - neither is true in this case
:feedback_e: This does not cause a run-time error because the loop stops before the division by zero would occur because of short-circuit evaluation where the first condition in the && is false when var2 is 0, so the second condition is not executed.

What are the values of var1 and var2 when the code finishes executing?

Expand All @@ -111,7 +111,7 @@ Did your trace table look like the following?
while ((var2 != 0) && ((var1 / var2) >= 0))
{
var1 = var1 + 1;
var2 = var2 -1;
var2 = var2 - 1;
}
.. mchoice:: qlb_2_3
Expand Down

0 comments on commit bdf70af

Please sign in to comment.