Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to print numbers from 1 to 3 using a loop.
Go
for i := 1; i <= [1]; i++ { fmt.Println(i) }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
๐ก Hint
Common Mistakes
Using a number too large or too small for the loop condition.
โ Incorrect
The loop runs while i is less than or equal to 3, printing numbers 1, 2, and 3.
2fill in blank
mediumComplete the code to sum numbers from 1 to 4 using a loop.
Go
sum := 0 for i := 1; i <= 4; [1] { sum += i } fmt.Println(sum)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
๐ก Hint
Common Mistakes
Using
i-- which decreases the variable and causes an infinite loop.โ Incorrect
The loop variable i increases by 1 each time to add all numbers from 1 to 4.
3fill in blank
hardFix the error in the loop to print numbers from 1 to 5.
Go
for i := 1; i < [1]; i++ { fmt.Println(i) }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
๐ก Hint
Common Mistakes
Using
i < 5 which stops before printing 5.โ Incorrect
Using i < 6 makes the loop print numbers 1 to 5 because it stops before 6.
4fill in blank
hardFill both blanks to create a loop that prints even numbers from 2 to 8.
Go
for i := [1]; i <= [2]; i += 2 { fmt.Println(i) }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
๐ก Hint
Common Mistakes
Starting at 1 or stopping before 8.
โ Incorrect
The loop starts at 2 and goes up to 8, increasing by 2 each time to print even numbers.
5fill in blank
hardFill all three blanks to create a loop that prints numbers from 10 down to 6.
Go
for i := [1]; i [2] [3]; i-- { fmt.Println(i) }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
๐ก Hint
Common Mistakes
Using
<= instead of >= in the condition.โ Incorrect
The loop starts at 10 and decreases by 1 until it reaches 6, printing numbers 10 to 6.