Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to print numbers from 1 to 5.
Kotlin
for (i in 1..[1]) { println(i) }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 6 instead of 5 includes an extra number.
Using 4 stops before 5.
✗ Incorrect
The range 1..5 includes numbers from 1 to 5.
2fill in blank
mediumComplete the code to print even numbers from 2 to 10 using step.
Kotlin
for (i in 2..10 step [1]) { println(i) }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using step 1 prints all numbers.
Using step 3 skips some even numbers.
✗ Incorrect
The step keyword controls the increment. For even numbers, step should be 2.
3fill in blank
hardFix the error in the code to print numbers from 5 down to 1.
Kotlin
for (i in 5 [1] 1) { println(i) }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '..' creates an increasing range, causing no output.
Using 'until' is for increasing ranges and excludes the end.
✗ Incorrect
The downTo keyword creates a decreasing range from 5 to 1.
4fill in blank
hardFill both blanks to print odd numbers from 9 down to 1.
Kotlin
for (i in 9 [1] 1 [2] 2) { println(i) }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '..' instead of 'downTo' counts up, not down.
Forgetting
step prints all numbers.✗ Incorrect
Use downTo for counting down and step 2 to skip even numbers.
5fill in blank
hardFill all three blanks to print numbers from 10 down to 2, stepping by 2.
Kotlin
for (i in [1] [2] [3]) { println(i) }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'until 2' counts up and excludes 2.
Placing
step before downTo causes syntax errors.✗ Incorrect
Start at 10, count down to 2 using downTo 2, and step by 2 with step 2.