PYTHON MULTIPLE CHOICE 1a) What is the output of the following code snippet?
fibonacci = {1, 1, 2, 3, 5, 8} primes = {2, 3, 5, 7, 11} both = fibonacci.union(primes) print(both)
1b) What is stored in x at the end of this code segment?
primes = {2, 3, 5, 7} odds = {1, 3, 5, 7} x = primes.intersection(odds)
1c) Which of the following statements creates a duplicate copy of the favoriteFoodsdictionary?
| favoriteFoods2 = copy(favoriteFoods) |
| favoriteFoods2 = dict(favoriteFoods) |
| favoriteFoods2 = duplicate(favoriteFoods) |
| favoriteFoods2 = favoriteFoods |
1d) You use______________ to delete an element from a dictionary.
1e) Consider the following dictionary:
favoriteFoods = {"Peg": "burgers", "Cy": "hotdogs", "Bob": "apple pie"}
What statement will print Peg's favorite food?
| print("Peg's favorite food is: ", favoriteFoods.get(1)) |
| print("Peg's favorite food is: ", favoriteFoods(Peg)) |
| print("Peg's favorite food is: ", favoriteFoods["Peg"]) |
| print("Peg's favorite food is: ", favoriteFoods[1]) |
1f) The_________method returns a randomly selected key-value pair from a dictionary.
1g) The_______________function returns the number of elements in a dictionary:
1h) The ________ method returns the value associated with a specified key and removes that key-value pair from the dictionary.
1i) The ______ method returns all of a dictionarys keys and their associated values as a sequence of tuples.
1j) Which statement correctly creates a dictionary for converting numbers 1 through 5 to roman numerals?
| numerals = {[1, "I"], [2, "II"], [3, "III"], [4, "IV"], [5, "V"]} |
| numerals = [1: "I", 2: "II", 3: "III", 4: "IV", 5: "V"] |
| numerals = (1: "I", 2: "II", 3: "III", 4: "IV", 5: "V") |
| numerals = {1: "I", 2: "II", 3: "III", 4: "IV", 5: "V"} |
1k) What is the difference between a list and a dictionary?
| a list is a subset of a dictionary |
| a dictionary can access elements by position |
| a list stores individual elements but a dictionary stores key/value pairs |
| list operations are much faster than the equivalent dictionary operations |
1l) What is returned by a dictionary's items method?
| A set of floating point numbers |