0
0
Pythonprogramming~10 mins

Logical operators in conditions 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 check if a number is positive and less than 10.

Python
if num > 0 [1] num < 10:
    print("Number is between 1 and 9")
Drag options to blanks, or click blank then click option'
Aand
Bor
Cnot
Dxor
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'or' instead of 'and' which allows numbers outside the range.
Using 'not' which negates a condition incorrectly.
2fill in blank
medium

Complete the code to check if a character is a vowel or a digit.

Python
if char in 'aeiou' [1] char.isdigit():
    print("It's a vowel or a digit")
Drag options to blanks, or click blank then click option'
Aand
Bxor
Cnot
Dor
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'and' which requires both conditions to be true.
Using 'not' which negates a condition incorrectly.
3fill in blank
hard

Fix the error in the condition to check if a number is not between 5 and 15.

Python
if num < 5 [1] num > 15:
    print("Number is outside 5 to 15")
Drag options to blanks, or click blank then click option'
Aand
Bor
Cxor
Dnot
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'and' which would never be true because a number can't be less than 5 and greater than 15 at the same time.
4fill in blank
hard

Fill both blanks to create a dictionary of words with length greater than 3 and containing letter 'a'.

Python
result = {word: len(word) for word in words if len(word) [1] 3 [2] 'a' in word}
Drag options to blanks, or click blank then click option'
A>
B<
Cand
Dor
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' for length comparison.
Using 'or' which includes words that don't meet both conditions.
5fill in blank
hard

Fill all three blanks to create a dictionary of uppercase keys and values for words longer than 4 or containing 'e'.

Python
result = [1]: [2] for word in words if len(word) [3] 4 or 'e' in word
Drag options to blanks, or click blank then click option'
Aword.upper()
Bword
C>
Dlen(word)
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'len(word)' as a key or value instead of the word itself.
Using '<' instead of '>' in the condition.