0
0
Pythonprogramming~10 mins

Lambda syntax and behavior 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 lambda function that adds 5 to its input.

Python
add_five = lambda x: x [1] 5
print(add_five(10))
Drag options to blanks, or click blank then click option'
A*
B-
C/
D+
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using subtraction or multiplication instead of addition.
Forgetting the operator between x and 5.
2fill in blank
medium

Complete the code to create a lambda function that returns True if a number is even.

Python
is_even = lambda n: n [1] 2 == 0
print(is_even(4))
Drag options to blanks, or click blank then click option'
A+
B%
C-
D*
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using addition or multiplication instead of modulo.
Forgetting to compare the result to zero.
3fill in blank
hard

Fix the error in the lambda function that should multiply input by 3.

Python
triple = lambda x: x [1] 3
print(triple(7))
Drag options to blanks, or click blank then click option'
A*
B+
C-
D/
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using addition or subtraction instead of multiplication.
Using division which changes the value incorrectly.
4fill in blank
hard

Fill in the blank to create a lambda that returns True if a word's length is greater than 4.

Python
check_length = lambda word: len(word) [1] 4
print(check_length('hello'))
Drag options to blanks, or click blank then click option'
A>
B<
C==
D!=
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using less than or equal operators instead of greater than.
Using equality operator which checks for exact length.
5fill in blank
hard

Fill all three blanks to create a lambda that filters numbers greater than 10 and doubles them.

Python
result = list(filter(lambda x: x [1] 10, map(lambda x: x [2] [3], [5, 12, 7, 15])))
print(result)
Drag options to blanks, or click blank then click option'
A>
B*
C2
D<
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using less than operator for filtering.
Using addition instead of multiplication for doubling.
Forgetting to provide the multiplier.