nerdexam
Cisco

200-901 · Question #473

Refer to the exhibit. An astronomer creates a Python script named makeexoplanetapi.py to import external data for comparison with the department data. The astronomer changes the script after a…

The correct answer is B. --- makeexoplanetapi.py 2020-12-20 19:30:32 +++ makeexoplanetapi.py 2020-12-20 19:30:32 @@ -1,4 +1,5 @@ import csv import json import requests -app = Flask(__name__) +add app = Flask(__name__) response = requests.post('https://httpbin.org') with open("planets_exo.csv", "r", encoding="utf-8-sig") as f: exo = json.load(f) with open("exo_api.csv", "w", encoding="utf-8-sig") sub = json.dumps(sub, indent=4) print(sub) with open("exo_api.csv", "r", encoding="utf-8-sig") sub_list = json.load(sub) add sub = json.dumps(sub, indent=4) print(exo). A unified diff represents file changes with specific header lines, hunk range markers, and '-' or '+' prefixes on changed lines.

Software Development and Design

Question

Refer to the exhibit. An astronomer creates a Python script named makeexoplanetapi.py to import external data for comparison with the department data. The astronomer changes the script after a discussion with another astronomer. Which code snippet shows a unified diff of the script? A. B. C. D.

Exhibits

200-901 question #473 exhibit 1
200-901 question #473 exhibit 2
200-901 question #473 exhibit 3
200-901 question #473 exhibit 4
200-901 question #473 exhibit 5

Options

  • A--- makeexoplanetapi.py 2020-12-20 19:30:32 +++ makeexoplanetapi.py 2020-12-20 19:30:32 @@ -8,3 +8,3 @@
    • app = Flask(name)
    • @app.route('/planets_data') with open("planets_exo.csv", "r", encoding="utf-8-sig") as f: exo = json.load(f) with open("exo_api.csv", "w", encoding="utf-8-sig") f.write(str(reader)) print(exo)
  • B--- makeexoplanetapi.py 2020-12-20 19:30:32 +++ makeexoplanetapi.py 2020-12-20 19:30:32 @@ -1,4 +1,5 @@ import csv import json import requests -app = Flask(name) +add app = Flask(name) response = requests.post('https://httpbin.org') with open("planets_exo.csv", "r", encoding="utf-8-sig") as f: exo = json.load(f) with open("exo_api.csv", "w", encoding="utf-8-sig") sub = json.dumps(sub, indent=4) print(sub) with open("exo_api.csv", "r", encoding="utf-8-sig") sub_list = json.load(sub) add sub = json.dumps(sub, indent=4) print(exo)
  • C--- makeexoplanetapi.py 2020-12-20 19:30:32 +++ makeexoplanetapi.py 2020-12-20 19:30:32 @@ -1,7 +1,8 @@ import csv import json import requests
    • app = Flask(name)
    • @app.route('/planets_data') with open("planets_exo.csv", "r", encoding="utf-8-sig") as f: exo = json.load(f) with open("exo_api.csv", "w", encoding="utf-8-sig") f.write(str(reader)) print(exo)
  • D--- makeexoplanetapi.py 2020-12-20 19:30:32 +++ makeexoplanetapi.py 2020-12-20 19:30:32 @@ -8,3 +8,3 @@ response = requests.post('https://httpbin.org')
    • app = Flask(name)
    • @app.route('/planets_data') with open("planets_exo.csv", "r", encoding="utf-8-sig") as f: exo = json.load(f) with open("exo_api.csv", "w", encoding="utf-8-sig") f.write(str(reader)) print(exo)

How the community answered

(36 responses)
  • A
    6% (2)
  • B
    92% (33)
  • C
    3% (1)

Why each option

A unified diff represents file changes with specific header lines, hunk range markers, and '-' or '+' prefixes on changed lines.

A--- makeexoplanetapi.py 2020-12-20 19:30:32 +++ makeexoplanetapi.py 2020-12-20 19:30:32 @@ -8,3 +8,3 @@ - response = requests.post('https://httpbin.org') + app = Flask(__name__) + @app.route('/planets_data') with open("planets_exo.csv", "r", encoding="utf-8-sig") as f: exo = json.load(f) with open("exo_api.csv", "w", encoding="utf-8-sig") f.write(str(reader)) print(exo)

The hunk header '@@ -8,3 +8,3 @@' places the change at line 8, which does not correspond to where an import-block modification would appear, making the line numbering structurally incorrect.

B--- makeexoplanetapi.py 2020-12-20 19:30:32 +++ makeexoplanetapi.py 2020-12-20 19:30:32 @@ -1,4 +1,5 @@ import csv import json import requests -app = Flask(__name__) +add app = Flask(__name__) response = requests.post('https://httpbin.org') with open("planets_exo.csv", "r", encoding="utf-8-sig") as f: exo = json.load(f) with open("exo_api.csv", "w", encoding="utf-8-sig") sub = json.dumps(sub, indent=4) print(sub) with open("exo_api.csv", "r", encoding="utf-8-sig") sub_list = json.load(sub) add sub = json.dumps(sub, indent=4) print(exo)Correct

A valid unified diff starts with '---' and '+++' file path headers, followed by '@@ -start,count +start,count @@' hunk headers, then uses '-' to prefix removed lines and '+' to prefix added lines, with unchanged context lines having no prefix. Option B correctly applies this structure, including the proper file headers and hunk notation showing the modified lines in the import block.

C--- makeexoplanetapi.py 2020-12-20 19:30:32 +++ makeexoplanetapi.py 2020-12-20 19:30:32 @@ -1,7 +1,8 @@ import csv import json import requests - response = requests.post('https://httpbin.org') + app = Flask(__name__) + @app.route('/planets_data') with open("planets_exo.csv", "r", encoding="utf-8-sig") as f: exo = json.load(f) with open("exo_api.csv", "w", encoding="utf-8-sig") f.write(str(reader)) print(exo)

Although the file headers are present, the hunk range '@@ -1,7 +1,8 @@' and the indented lines marked as changed do not accurately reflect a top-level single-line replacement in the import section.

D--- makeexoplanetapi.py 2020-12-20 19:30:32 +++ makeexoplanetapi.py 2020-12-20 19:30:32 @@ -8,3 +8,3 @@ response = requests.post('https://httpbin.org') - app = Flask(__name__) + @app.route('/planets_data') with open("planets_exo.csv", "r", encoding="utf-8-sig") as f: exo = json.load(f) with open("exo_api.csv", "w", encoding="utf-8-sig") f.write(str(reader)) print(exo)

The diff incorrectly marks the Flask app initialization line as removed and the route decorator as added, reversing the actual direction of the change between the original and revised script.

Concept tested: Unified diff format for representing code changes

Source: https://www.gnu.org/software/diffutils/manual/html_node/Unified-Format.html

Topics

#unified diff#version control#code comparison

Community Discussion

No community discussion yet for this question.

Full 200-901 Practice