0
0
Pythonprogramming~10 mins

Math-related operations 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 square of 4.

Python
result = 4 [1] 2
print(result)
Drag options to blanks, or click blank then click option'
A+
B*
C**
D//
Attempts:
3 left
💡 Hint
Common Mistakes
Using '*' instead of '**' will multiply but not raise to power.
Using '+' will add numbers instead of exponentiation.
2fill in blank
medium

Complete the code to find the remainder when 17 is divided by 5.

Python
remainder = 17 [1] 5
print(remainder)
Drag options to blanks, or click blank then click option'
A%
B*
C//
D+
Attempts:
3 left
💡 Hint
Common Mistakes
Using '//' gives the quotient, not the remainder.
Using '*' or '+' will not give the remainder.
3fill in blank
hard

Fix the error in the code to calculate the integer division of 15 by 4.

Python
result = 15 [1] 4
print(result)
Drag options to blanks, or click blank then click option'
A%
B*
C/
D//
Attempts:
3 left
💡 Hint
Common Mistakes
Using '/' returns a float, not an integer.
Using '%' returns the remainder, not the quotient.
4fill in blank
hard

Fill both blanks to create a dictionary of squares for numbers 1 to 5, but only include squares greater than 10.

Python
squares = {x: x[1]2 for x in range(1, 6) if x[1]2[2]10}
print(squares)
Drag options to blanks, or click blank then click option'
A**
B*
C>
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using '*' instead of '**' will multiply but not square.
Using '<' instead of '>' will filter the wrong numbers.
5fill in blank
hard

Fill all three blanks to create a dictionary with uppercase keys, values as numbers, and only include values greater than 2.

Python
result = [1]: [2] for [3], [2] in {'a':1, 'b':3, 'c':5}.items() if [2] > 2}
print(result)
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' and 'v' for loop variables.
Not converting keys to uppercase.
Mixing up keys and values in the dictionary comprehension.