PYTHON MULTIPLE CHOICE 1a) The ______ method returns all of a dictionarys keys and their associated values as a sequence of tuples.
1b) The ________ method returns the value associated with a specified key and removes that key-value pair from the dictionary.
1c) Which statement correctly creates a set named colors that contains the 7 colors in a rainbow?
| colors = ["red", "orange", "yellow" "green", "blue", "indigo", "violet"] |
| colors = {red, orange, yellow, green, blue, indigo, violet} |
| colors = [red, orange, yellow, green, blue, indigo, violet] |
| colors = {"red", "orange", "yellow", "green", "blue", "indigo", "violet"} |
1d) Which of the following code segments prints red is a color of the rainbow when the set colors contains the string "red"?
| if colors contains "red": print("red is a color of the rainbow") |
| if "red" in colors: print("red is a color of the rainbow") |
| if "red" not in colors: print("red is a color of the rainbow") |
| if colors includes "red": print("red is a color of the rainbow") |
1e) How can you print all the elements in the set colors each on a separate line?
| for i in range(len(colors)): print(colors[i]) |
| for color in colors: print(color) |
| for i in range(0, len(colors)): print(colors[i]) |
1f) Which statement(s) below print the set colors in sorted order?
| for i in range(len(colors)): print(colors[i]) |
| for color in sorted(colors): print(color) |
| for color in colors.sorted(): print(color) |
| for i in range(len(colors)): print(sorted(colors[i])) |
1g) Given the following code snippet, which statement tests to see if all three sets are equal?
fruit = set(["apple", "banana", "grapes", "kiwi"]) fruit2 = set(["apple", "banana", "grapes", "kiwi"]) fruit3 = set(["apple", "banana", "pears", "kiwi"])
| if fruit.equal(fruit2) and fruit.equal(fruit3): |
| if fruit == fruit2 and fruit == fruit3: |
| if fruit != fruit2 and fruit != fruit3: |
| if fruit == fruit2 or fruit == fruit3: |