0
0
Pythonprogramming~10 mins

Set creation 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 create a set with the numbers 1, 2, and 3.

Python
my_set = [1]
Drag options to blanks, or click blank then click option'
A(1, 2, 3)
B[1, 2, 3]
C{1, 2, 3}
D"1, 2, 3"
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using square brackets [] creates a list, not a set.
Using parentheses () creates a tuple, not a set.
2fill in blank
medium

Complete the code to create an empty set.

Python
empty_set = [1]
Drag options to blanks, or click blank then click option'
A{}
Bset()
C[]
Dempty()
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using {} creates an empty dictionary, not a set.
Using [] creates an empty list, not a set.
3fill in blank
hard

Fix the error in the code to create a set from a list.

Python
numbers = [1, 2, 3, 4]
my_set = [1]
Drag options to blanks, or click blank then click option'
A(numbers)
B{numbers}
C[numbers]
Dset(numbers)
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using {numbers} tries to put the whole list inside a set, causing an error.
Using square or round brackets does not create a set.
4fill in blank
hard

Complete the code to create a set of squares for numbers 1 to 5.

Python
squares = { x**2 for x in range(1, 6) if x [1] 3 }
Drag options to blanks, or click blank then click option'
A{
B[
C>
D<=
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using square brackets creates a list, not a set.
Using the wrong comparison operator changes the filtered numbers.
5fill in blank
hard

Fill both blanks to create a set of uppercase letters from a list, filtering only letters after 'm'.

Python
letters = ['a', 'b', 'm', 'n', 'z']
result = [ letter for letter in letters if letter [1] 'm' ]
result = {x[2] for x in result}
Drag options to blanks, or click blank then click option'
A{letter.upper()}
B>
C.upper()
D[
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using curly braces in the first line creates a set, not a list.
Using the wrong comparison operator filters wrong letters.
Forgetting to convert letters to uppercase.