0
0
Pythonprogramming~10 mins

Operator precedence and evaluation order 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 calculate the correct result using operator precedence.

Python
result = 3 + 4 * [1]
Drag options to blanks, or click blank then click option'
A1
B2
C5
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Adding 3 + 4 first, then multiplying by the number.
2fill in blank
medium

Complete the code to get the correct boolean result using operator precedence.

Python
result = True or False and [1]
Drag options to blanks, or click blank then click option'
ATrue
B0
CNone
DFalse
Attempts:
3 left
💡 Hint
Common Mistakes
Evaluating True or False first.
3fill in blank
hard

Fix the error in the expression to get the correct result.

Python
result = (10 - 3) [1] 2 ** 3
Drag options to blanks, or click blank then click option'
A*
B-
C+
D/
Attempts:
3 left
💡 Hint
Common Mistakes
Using + or - instead of * changes the result.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that includes only even squares.

Python
squares = {x: x[1]2 for x in range(1, 6) if x [2] 2 == 0}
Drag options to blanks, or click blank then click option'
A**
B%
C//
D+
Attempts:
3 left
💡 Hint
Common Mistakes
Using // instead of % for checking even numbers.
5fill in blank
hard

Fill all three blanks to create a filtered dictionary with uppercase keys and values greater than zero.

Python
result = [1]: [2] for [3], v in data.items() if v > 0}
Drag options to blanks, or click blank then click option'
Ak.upper()
Bv
Ck
Ditem
Attempts:
3 left
💡 Hint
Common Mistakes
Using item instead of k as the loop variable.