Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to split the list into two lists based on a condition.
Kotlin
val numbers = listOf(1, 2, 3, 4, 5) val (even, odd) = numbers.partition { it [1] 2 == 0 }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using division operator instead of modulo
Using incorrect operator like 'mod' which is not valid syntax
✗ Incorrect
The '%' operator is used to get the remainder, so 'it % 2 == 0' checks if a number is even.
2fill in blank
mediumComplete the code to partition words by length greater than 3.
Kotlin
val words = listOf("cat", "house", "dog", "elephant") val (longWords, shortWords) = words.partition { it.length [1] 3 }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' which selects shorter words
Using '==' which selects words exactly length 3
✗ Incorrect
We want words longer than 3, so the condition is 'it.length > 3'.
3fill in blank
hardFix the error in the partition condition to split numbers divisible by 3.
Kotlin
val nums = listOf(3, 4, 6, 7, 9) val (divByThree, others) = nums.partition { it [1] 3 == 0 }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using division '/' instead of modulo
Using multiplication '*' which is incorrect
✗ Incorrect
The modulo operator '%' checks divisibility by 3 correctly.
4fill in blank
hardFill both blanks to partition a list of strings into those starting with 'a' and others.
Kotlin
val fruits = listOf("apple", "banana", "avocado", "cherry") val (aFruits, otherFruits) = fruits.partition { it[1].startsWith([2]) }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '->' instead of '.'
Using single quotes for string literal
✗ Incorrect
Use '.' to call the method and double quotes for string literal "a".
5fill in blank
hardFill all three blanks to partition a list of integers into positives and non-positives.
Kotlin
val numbers = listOf(-1, 0, 2, 3, -5) val (positive, nonPositive) = numbers.partition { it [1] [2] 0 [3] }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' which selects negatives
Using '==' which selects only zero
✗ Incorrect
The condition 'it > 0' selects positives; 'it >= 0' and 'it == 0' are common comparisons but only 'it > 0' is needed here.