MAT 215 Chapter 6 Exam With
Complete Solutions
Which of the following statements is false?
a. Lists and tuples are built-in sequence collections.
b. Dictionaries, strings and sets are built-in non-sequence collections.
c. A dictionary is an unordered collection which stores key-value pairs that map
immutable keys to values,
just as a conventional dictionary maps words to definitions.
d. A set is an unordered collection of unique immutable elements. - ANSWER
Answer: b. Actually, dictionaries and sets are built-in non-sequence collections,
but strings are
built-in sequence collections
Which of the following statements a), b) or c) is false?
a. A dictionary associates keys with values. Each key maps to a specific value.
b. A dictionary's keys must be mutable (such as strings, numbers or tuples) and
unique (that is, no
duplicates).
c. Multiple keys can have the same value, such as two different inventory codes
that have the same
quantity in stock.
d. All of the above statements are true. - ANSWER Answer: b. Actually, a
dictionary's keys must be immutable (such as strings, numbers or tuples)
and unique (that is, no duplicates)
Which of the following statements is false?
a. You can create a dictionary by enclosing in curly braces, {}, a comma-
separated list of key-value pairs,
each of the form key: value.
b. You can create an empty dictionary with {}.
c. The following statement creates a dictionary with the country-name keys
'Finland', 'South Africa'
and 'Nepal' and their corresponding Internet country code values 'fi', 'za' and
'np':
country_codes = {'Finland', 'fi', 'South Africa', 'za',
'Nepal', 'np'}
d. When you output a dictionary, its comma-separated list of key-value pairs is
always enclosed in curly
braces. - ANSWER Answer: c. Actually, the following code creates a dictionary
with the country-name keys
, 'Finland', 'South Africa' and 'Nepal' and their corresponding Internet country
code values
'fi', 'za' and 'np':
country_codes = {'Finland': 'fi', 'South Africa': 'za',
'Nepal': 'np'}
Which of the following statements is false?
a. When you pass a dictionary to built-in function len, the function returns the
number of key-value pairsin the dictionary.
b. You can use a dictionary as a condition to determine if it's empty—a non-
empty dictionary evaluates to
True.
c. An empty dictionary evaluates to False.
d. Method clean deletes the dictionary's key-value pairs: - ANSWER Answer: d.
Actually, method clear deletes the dictionary's key-value pairs.
terating through a Dictionary
6.2 Q4: Which of the following statements a), b) and c) is false?
a. The following dictionary maps month-name strings to int values representing
the numbers of days in
the corresponding month:
days_per_month = {'January' : 31 , 'February' : 28 , 'March' : 31 }
b. Multiple keys in a dictionary can have the same value.
c. The following for statement iterates through dictionary days_per_month's key-
value pairs.
Dictionary method items returns each key-value pair as a tuple, which is
unpacked into the target
variables month and days:
for month, days in days_per_month.items():
print(f' {month} has {days} days' )
d. All of the above statements are true. - ANSWER Answer: b. Actually, multiple
values in a dictionary can have the same value. Keys must be unique
Which of the following statements a), b) or c) is false?
a. The following code creates the dictionary roman_numerals, which maps
roman numerals to their
integer equivalents (the value for 'X' is intentionally wrong):
roman_numerals = {'I' : 1 , 'II' : 2 , 'III' : 3 , 'V' : 5 , 'X' : 100 }
b. The following code gets the value associated with the key 'V' in Part (a):
roman_numerals['V' ]
c. You can update a key's associated value in an assignment statement. The
following code replaces the
incorrect value associated with the key 'X' in Part (a):
roman_numerals['X' ] = 10
d. All of the above statements are true. - ANSWER Answer: d.
Complete Solutions
Which of the following statements is false?
a. Lists and tuples are built-in sequence collections.
b. Dictionaries, strings and sets are built-in non-sequence collections.
c. A dictionary is an unordered collection which stores key-value pairs that map
immutable keys to values,
just as a conventional dictionary maps words to definitions.
d. A set is an unordered collection of unique immutable elements. - ANSWER
Answer: b. Actually, dictionaries and sets are built-in non-sequence collections,
but strings are
built-in sequence collections
Which of the following statements a), b) or c) is false?
a. A dictionary associates keys with values. Each key maps to a specific value.
b. A dictionary's keys must be mutable (such as strings, numbers or tuples) and
unique (that is, no
duplicates).
c. Multiple keys can have the same value, such as two different inventory codes
that have the same
quantity in stock.
d. All of the above statements are true. - ANSWER Answer: b. Actually, a
dictionary's keys must be immutable (such as strings, numbers or tuples)
and unique (that is, no duplicates)
Which of the following statements is false?
a. You can create a dictionary by enclosing in curly braces, {}, a comma-
separated list of key-value pairs,
each of the form key: value.
b. You can create an empty dictionary with {}.
c. The following statement creates a dictionary with the country-name keys
'Finland', 'South Africa'
and 'Nepal' and their corresponding Internet country code values 'fi', 'za' and
'np':
country_codes = {'Finland', 'fi', 'South Africa', 'za',
'Nepal', 'np'}
d. When you output a dictionary, its comma-separated list of key-value pairs is
always enclosed in curly
braces. - ANSWER Answer: c. Actually, the following code creates a dictionary
with the country-name keys
, 'Finland', 'South Africa' and 'Nepal' and their corresponding Internet country
code values
'fi', 'za' and 'np':
country_codes = {'Finland': 'fi', 'South Africa': 'za',
'Nepal': 'np'}
Which of the following statements is false?
a. When you pass a dictionary to built-in function len, the function returns the
number of key-value pairsin the dictionary.
b. You can use a dictionary as a condition to determine if it's empty—a non-
empty dictionary evaluates to
True.
c. An empty dictionary evaluates to False.
d. Method clean deletes the dictionary's key-value pairs: - ANSWER Answer: d.
Actually, method clear deletes the dictionary's key-value pairs.
terating through a Dictionary
6.2 Q4: Which of the following statements a), b) and c) is false?
a. The following dictionary maps month-name strings to int values representing
the numbers of days in
the corresponding month:
days_per_month = {'January' : 31 , 'February' : 28 , 'March' : 31 }
b. Multiple keys in a dictionary can have the same value.
c. The following for statement iterates through dictionary days_per_month's key-
value pairs.
Dictionary method items returns each key-value pair as a tuple, which is
unpacked into the target
variables month and days:
for month, days in days_per_month.items():
print(f' {month} has {days} days' )
d. All of the above statements are true. - ANSWER Answer: b. Actually, multiple
values in a dictionary can have the same value. Keys must be unique
Which of the following statements a), b) or c) is false?
a. The following code creates the dictionary roman_numerals, which maps
roman numerals to their
integer equivalents (the value for 'X' is intentionally wrong):
roman_numerals = {'I' : 1 , 'II' : 2 , 'III' : 3 , 'V' : 5 , 'X' : 100 }
b. The following code gets the value associated with the key 'V' in Part (a):
roman_numerals['V' ]
c. You can update a key's associated value in an assignment statement. The
following code replaces the
incorrect value associated with the key 'X' in Part (a):
roman_numerals['X' ] = 10
d. All of the above statements are true. - ANSWER Answer: d.