Skip to content

Module 2 Graded Quiz: Python Data Structures ::Python for Data Science, AI & Development (IBM Data Science Professional Certificate) Answers 2025

1. Question 1

Access only the test group measurements from:
experiment_data = ((1.5, 2.7), [3.6, 4.1])

  • ✅ experiment_data[1]

  • ❌ experiment_data[0]

  • ❌ experiment_data[0:1]

  • ❌ experiment_data[1][0]

Explanation:
Index 1 contains the test group list [3.6, 4.1].


2. Question 2

Key difference when accessing elements in a nested tuple:

  • ✅ Nested tuple structures require multiple indices to access inner elements.

  • ❌ Always returns another tuple

  • ❌ Need negative indices

  • ❌ Use parentheses for nested indexing

Explanation:
Nested structures are accessed like: data[1][0].


3. Question 3

What happens after cart.append(['hat', 'belt'])?

  • ✅ [‘shirt’, ‘pants’, [‘hat’, ‘belt’]]

  • ❌ [‘shirt’, ‘pants’, ‘hat’, ‘belt’]

  • ❌ [‘hat’, ‘belt’, ‘shirt’, ‘pants’]

  • ❌ [[‘hat’, ‘belt’], ‘shirt’, ‘pants’]

Explanation:
.append() adds the entire list as one item, not individually.


4. Question 4

Effect of del on lists:

  • ❌ Creates copy

  • ❌ Works only on first/last elements

  • ❌ Returns removed element

  • ✅ Permanently modifies the original list by removing specified elements.

Explanation:
del list[index] removes items in place.


5. Question 5

Why create proper list copies instead of direct assignment?

  • ❌ Uses less memory

  • ✅ Changes to a copied list do NOT affect the original; direct assignment links both lists.

  • ❌ Only needed for numeric data

  • ❌ Direct assignment is deprecated

Explanation:
Assignment creates an alias: b = a
Copying: b = a.copy() or b = a[:]


6. Question 6

Result of:
("Python", "Data", "Science")[1:3]

  • ❌ (“Python”, “Science”)

  • ❌ [“Python”, “Data”]

  • ✅ (“Data”, “Science”)

  • ❌ [“Data”, “Science”]

Explanation:
Slice returns items at indices 1 and 2, in tuple form.


7. Question 7

Values of:
{"The Bodyguard":"1992", "Saturday Night Fever":"1977"}

  • ❌ “The Bodyguard” and “Saturday Night Fever”

  • ❌ “1992” and “Saturday Night Fever”

  • ❌ “The Bodyguard” and “1977”

  • ✅ “1977” and “1992”

Explanation:
Values = release years.


8. Question 8

How to add or update a dictionary entry?

  • ✅ Use square bracket notation with the key to assign/update the value.

  • ❌ insert()

  • ❌ Dictionaries are immutable

  • ❌ add()

Example:
my_dict['new_key'] = 'value'


9. Question 9

Result of:
V = {'A','B'}
V.add('C')

  • ❌ {‘A’,’B’}

  • ❌ Error

  • ❌ {‘AC’, ‘BC’}

  • ✅ {‘A’,’B’,’C’}

Explanation:
Sets simply add elements if not present.


10. Question 10

Check if ‘B456’ is authorized:

  • ❌ auth_codes == ‘B456’

  • ❌ auth_codes.contains(‘B456’) (not valid)

  • ❌ auth_codes.find(‘B456’)

  • ✅ ‘B456’ in auth_codes

Explanation:
in checks membership in a set.


🧾 Summary Table

Q# Correct Answer Concept
1 experiment_data[1] Access nested data
2 Multiple indices Nested tuple access
3 [‘shirt’,’pants’,[‘hat’,’belt’]] append() behavior
4 del modifies list Deletes in place
5 Copy prevents shared changes List copying
6 (“Data”,”Science”) Tuple slicing
7 “1977”,”1992″ Dictionary values
8 dict[key] = value Update dict entries
9 {‘A’,’B’,’C’} Set add()
10 ‘B456’ in auth_codes Membership check