0
0
Pythonprogramming~10 mins

Subset and superset checks in Python - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to check if set A is a subset of set B.

Python
A = {1, 2, 3}
B = {1, 2, 3, 4, 5}
result = A.[1](B)
print(result)
Drag options to blanks, or click blank then click option'
Aissubset
Bissuperset
Cunion
Dintersection
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using 'issuperset' instead of 'issubset'.
Using 'union' or 'intersection' which return new sets, not booleans.
2fill in blank
medium

Complete the code to check if set B is a superset of set A.

Python
A = {1, 2}
B = {1, 2, 3, 4}
result = B.[1](A)
print(result)
Drag options to blanks, or click blank then click option'
Aissuperset
Bissubset
Cdifference
Dsymmetric_difference
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using 'issubset' instead of 'issuperset'.
Using set operations that return sets instead of booleans.
3fill in blank
hard

Fix the error in the code to check if set A is a subset of set B.

Python
A = {5, 6}
B = {4, 5, 6, 7}
result = A.[1](B)
print(result)
Drag options to blanks, or click blank then click option'
Aissuperset
Bissuper
Cissubset
Dsubset
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using non-existent methods like 'issuper' or 'subset'.
Confusing 'issubset' with 'issuperset'.
4fill in blank
hard

Fill both blanks to create a dictionary of words and their lengths, including only words longer than 3 letters.

Python
words = ['apple', 'bat', 'carrot', 'dog']
lengths = {word: [1] for word in words if len(word) [2] 3}
print(lengths)
Drag options to blanks, or click blank then click option'
Alen(word)
B>
C<
Dword
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using the word itself instead of its length.
Using '<' instead of '>' causing wrong filtering.
5fill in blank
hard

Fill all three blanks to create a dictionary with uppercase keys and values only if the value is greater than 0.

Python
data = {'a': 1, 'b': 0, 'c': 3}
result = { [1]: [2] for k, v in data.items() if v [3] 0 }
print(result)
Drag options to blanks, or click blank then click option'
Ak.upper()
Bv
C>
Dk
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using original keys instead of uppercase keys.
Filtering with '<' instead of '>'.
Using keys as values by mistake.