Complete the code to create a list of numbers from 0 to 5.
numbers = list(range([1]))
The range(6) function generates numbers from 0 up to 5, so the list will contain numbers 0 to 5. Since we want numbers 1 to 5, we will adjust in later tasks.
Complete the code to create a dictionary that maps numbers to their squares for numbers 1 to 5.
squares = {x: x[1]2 for x in range(1, [2])}* instead of ** will multiply but not square.range(1, 5) will exclude 5.The ** operator is used for exponentiation in Python. The range(1, 6) generates numbers from 1 to 5.
Fix the error in the code to check if a value exists in a list.
if [1] in my_list: print("Found it!")
To check if a value is in a list, you use the syntax value in list. Here, value is the item you want to find.
Fill both blanks to create a set of unique numbers from a list.
unique_numbers = set([1]) print(len([2]))
list or set as variable names incorrectly.The set() function creates a set of unique elements from the list numbers. Then, len(unique_numbers) gives the count of unique numbers.
Fill all three blanks to create a dictionary comprehension filtering even numbers and mapping to their squares.
even_squares = { [1]: [2] for [3] in range(1, 11) if [3] % 2 == 0 }The dictionary comprehension uses x as the key and x**2 as the value for even numbers x from 1 to 10.