{ "q1": { "type": "multiple", "question": "\n
Given the following Python script, echo.py:
\n\n\n#!/usr/bin/env python3\n\nimport sys\n\nfor arg in sys.argv[1:]:\n print(arg)\n\n\n
Which of the following statements are true (select all that apply)?
\n", "responses": { "module": "The line import sys loads the sys Python module.", "argv": "The command-line arguments to the script are stored in sys.argv.", "first": "Due to the [1:], the script only prints out the first argument.", "print": "It is not necessary to include the parentheses in the print function.", "arg": "The arg variable needs a $ in front of it just like in shell.", "shebang": "The shebang is necessary if we want to run the script with ./echo.py." } }, "q2": { "type": "multiple", "question": "\nGiven the following Python script, env.py:
\n\n\n#!/usr/bin/env python3\n\nimport os\n\nfor key, value in sorted(os.environ.items()):\n print('{}={}'.format(key, value))\n\n\n
Which of the following statements are true (select all that apply)?
\n", "responses": { "dict": "The os.environ is a dictionary object.", "list": "The os.environ is a list object.", "svars": "This script prints all the variables inside the script.", "evars": "This script prints all environmental variables from the shell.", "nofmt": "Instead of print('{}={}'.format(key, value)), we could do print(key + '=' + value).", "oldfmt": "Instead of print('{}={}'.format(key, value)), we could do print(f'{key}={value}')." } }, "q3": { "type": "multiple", "question": "\nGiven the following Python script, pokemon.py:
\n\n\n#!/usr/bin/env python3\n\nPokemon = ['pikachu', 'charmander', 'bulbasaur', 'squirtle']\n\nfor pokemon in Pokemon:\n if pokemon.endswith('r'):\n print(pokemon.upper())\n else:\n print(pokemon.title())\n\n\n
Which of the following statements are true (select all that apply)?
\n", "responses": { "append": "To add 'meowth' to the list of Pokemon, we could do Pokemon.append('meowth').", "push_back": "To add 'meowth' to the list of Pokemon, we could do Pokemon.push_back('meowth').", "last_item": "To access the last item in the Pokemon list, we could do Pokemon[-1]", "endswith": "The pokemon.endswith('r') checks if the string ends with the letter r.", "upper": "The pokemon.upper() permanently converts the current pokemon string into upper-case.", "output": "The output of this script is PIKACHU CHARMANDER BULBASAUR SQUIRTLE (where each word is on a separate line)." } }, "q4": { "type": "multiple", "question": "\nWhich of the following statements about lists and\ndictionaries are true (select all that apply)?
\n", "responses": { "datatypes": "Unlike a list, a dictionary can use many different data types as its index.", "updated": "Unlike a list, a dictionary cannot be updated after it has been declared.", "collection": "Like a list, a dictionary is a collection of many values.", "sliced": "Like a list, a dictionary can be sliced." } }, "q5": { "type": "blank", "question": "\nGiven the following Python script, hp.py:
\n\n\n#!/usr/bin/env python3\n\nname = 'Harry Potter and the Chamber of Secrets'\ncounts = {}\n\nfor letter in name.lower():\n counts[letter] = counts.get(letter, 0) + 1\n\n\n
After executing the code in the hp.py script, what are the\nfollowing values?
\n\nGiven the following Python script, words.py:\n\n
\n#!/usr/bin/env python3\n\nwords = 'DeBartolo Hall 102 is always so empty'\nfor word in words.split():\nprint(' '.join(result))\n keep = False\n for letter in word:\nresult = []\n result.append(word)\n keep = True\n if letter.isdecimal():\n if keep:\n\n\n
The code is suppose to remove all the words in the string that contain\nany numbers. For instance, executing the script above should print out:\n\"DeBartolo Hall is always so empty\". Unfortunately, the lines of code are\nscrambled. Unscramble them below so that the script produces the correct\noutput.
\n", "responses": { "1": "words = 'DeBartolo Hall 102 is always so empty'", "2": "for word in words.split():", "3": "print(' '.join(result))", "4": " keep = False", "5": " for letter in word:", "6": "result = []", "7": " result.append(word)", "8": " keep = True", "9": " if letter.isdecimal():", "10": " if keep:" } } }