{ "q1": { "type": "order", "question": "\nGiven the following Python script, courses.py:\n\n
\nfor course, count in sorted(counts.items(), key=lambda p: (-p[1], p[0])):\nfor course in re.findall(r'CSE [0-9]{5}', data):\n    counts[course] = counts.get(course, 0) + 1\n    print(f'{count:>7} {course}')\ndata   = requests.get('https://www3.nd.edu/~pbui/teaching/').text\ncounts = {}\n
\n\nThis script is suppose to extract all the CSE courses taught by the\ninstructor from his website and print out a count of how often each course\nwas taught in descending order by occurrence.\n\n
\n$ ./courses.py\n      9 CSE 20289\n      8 CSE 30341\n      ...\n      1 CSE 40850\n      1 CSE 40872\n      1 CSE 40881\n
\n\n

Unfortunately, the lines of code are scrambled. Unscramble them below so\nthat the script produces the correct output. Note: You can assume\nrequests and re are already imported.

\n", "responses": { "a": "for course, count in sorted(counts.items(), key=lambda p: (-p[1], p[0])):", "b": "for course in re.findall(r'CSE [0-9]{5}', data):", "c": "counts[course] = counts.get(course, 0) + 1", "d": "print(f'{count:>7} {course}')", "e": "data = requests.get('https://www3.nd.edu/~pbui/teaching/').text", "f": "counts = {}" } }, "q2": { "type": "blank", "question": "\nGiven the following Python script, shells.py:\n\n
\nshells = ____\nfor record in csv.reader(____, delimiter=____):\n    shells.add(____)\n\nfor shell in sorted(shells):\n    print(shell)\n
\n\nThis script is suppose to print out all of the shells in\n/etc/passwd in sorted order and without any duplicates.\n\n
\n$ ./shells.py\n/bin/bash\n/bin/false\n/bin/sync\n/usr/sbin/nologin\n
\n\nComplete this script by filling in the blanks.\n" }, "q3": { "type": "blank", "question": "\nGiven the following Python script, machines.py:\n\n
\nimport requests\n\nURL = 'http://catalog.cse.nd.edu:9097/query.json'\n\nresponse = ____\ndata     = ____\n\nfor machine in data:\n    if ____  == 'chirp':\n        print(____, ____)\n
\n\nThis script parses the JSON data from\nhttp://catalog.cse.nd.edu:9097/query.json, which contains a\nlisting of all the machines and services registered with Cooperative Computing Lab, and displays\nthe name and address of the machines with the type\nchirp.\n\n
\n$ ./machines.py\n140.221.79.11 140.221.79.11\ncamd01.crc.nd.edu 10.32.77.80\ncamd02.crc.nd.edu 10.32.77.82\ncamd03.crc.nd.edu 10.32.77.84\ncamd04.crc.nd.edu 10.32.77.86\n...\n
\n\nComplete this script by filling in the blanks.\n" } }