Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to print a message only if the number is positive.
Python
number = 5 if number [1] 0: print("Number is positive")
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' will check if the number is negative, which is not what we want.
✗ Incorrect
The condition number > 0 checks if the number is positive.
2fill in blank
mediumComplete the code to print 'Even' if the number is divisible by 2.
Python
number = 8 if number [1] 2 == 0: print("Even")
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '//' gives the quotient, not the remainder.
✗ Incorrect
The modulus operator % gives the remainder. If remainder is 0, number is divisible by 2.
3fill in blank
hardFix the error in the code to check if a number is not zero.
Python
number = 0 if number [1] 0: print("Number is not zero")
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' checks equality, which is the opposite of what we want.
✗ Incorrect
The operator != means 'not equal to', so it checks if number is not zero.
4fill in blank
hardFill both blanks to create a dictionary of squares for numbers greater than 3.
Python
squares = {x: x[1]2 for x in range(1, 6) if x [2] 3} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '%' instead of '**' will not square the number.
✗ Incorrect
Use ** to square the number and > to check if number is greater than 3.
5fill in blank
hardFill all three blanks to create a dictionary of uppercase keys and values greater than zero.
Python
result = [1]: [2] for k, v in data.items() if v [3] 0}
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'k' instead of 'k.upper()' will not change key case.
✗ Incorrect
Use k.upper() to make keys uppercase, v as values, and > to filter values greater than zero.