200-901 Question 168
Select 2You are reviewing changes to a Python project stored in a Git repository. Your teammate has submitted a pull request, and you run the 'git diff' command to compare the changes in the branch to the main branch. The unified diff output includes the following lines:
@@ -10,7 +10,7 @@
def calculate_sum(a, b):
# Adding two numbers
- return a + b
+ return a - b
@@ -25,6 +25,7 @@
print("Welcome to the calculator app!")
calculate_sum(5, 3)
+print("Subtraction feature added")
What can you infer from this unified diff output?
- A
A line was removed where the 'calculate_sum' function previously added two numbers.
- B
The 'calculate_sum' function was modified to subtract two numbers instead of adding.
- C
A new feature was added to perform subtraction instead of addition.
- D
A new print statement was added to the code after the call to 'calculate_sum'.
- E
The 'print("Welcome to the calculator app!")' line was removed.
Show answer and explanation
Correct answers: B, D
Explanation
In a unified diff, lines prefixed with '-' indicate content removed, '+' indicates content added, and lines without prefixes remain unchanged. The diff output shows the return statement in the 'calculate_sum' function was modified to subtract instead of add. Additionally, a new print statement was added after the call to 'calculate_sum'.
- A. Incorrect.
This is incorrect because the unified diff does not indicate a line was removed; rather, it shows a change to the existing 'calculate_sum' function.
- B. Correct.
This is correct because the diff shows that the return statement in the 'calculate_sum' function was changed from 'a + b' to 'a - b'.
- C. Incorrect.
This is incorrect because the diff does not indicate that a subtraction feature as a new function was added. It only modifies the existing behavior of 'calculate_sum'.
- D. Correct.
This is correct because the diff shows that a new line, '+print("Subtraction feature added")', was added to the code.
- E. Incorrect.
This is incorrect because the diff does not show the removal of the 'print("Welcome to the calculator app!")' line. That line remains unchanged.