Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to append a value to the end of the slice.
DSA Go
numbers := []int{1, 2, 3}
numbers = append(numbers, [1])
fmt.Println(numbers)Attempts:
3 left
💡 Hint
Common Mistakes
Using append without assignment back to the slice.
Appending a value not matching the slice type.
✗ Incorrect
Appending 4 adds it to the end of the slice, resulting in [1 2 3 4].
2fill in blank
mediumComplete the code to add the value 10 at the end of the slice.
DSA Go
data := []int{5, 6, 7}
data = append(data, [1])
fmt.Println(data)Attempts:
3 left
💡 Hint
Common Mistakes
Appending a wrong number.
Not assigning the result of append back to the slice.
✗ Incorrect
Appending 10 adds it to the end, resulting in [5 6 7 10].
3fill in blank
hardFix the error in the code to correctly append 15 to the slice.
DSA Go
values := []int{10, 11, 12}
values = append([1], 15)
fmt.Println(values)Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong variable name in append.
Forgetting to assign append result back to the slice.
✗ Incorrect
The slice variable is 'values', so append must use it to add 15.
4fill in blank
hardFill both blanks to append 20 to the slice and print the result.
DSA Go
nums := []int{16, 17, 18}
nums = [1](nums, [2])
fmt.Println(nums)Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong function name instead of append.
Adding the wrong value.
✗ Incorrect
Use append to add 20 to nums, resulting in [16 17 18 20].
5fill in blank
hardFill all three blanks to append 25 to the slice and print it.
DSA Go
arr := []int{21, 22, 23}
arr = [1](arr, [2])
fmt.[3](arr)Attempts:
3 left
💡 Hint
Common Mistakes
Using fmt.Print instead of fmt.Println.
Appending wrong value or forgetting to assign back.
✗ Incorrect
Use append to add 25 and fmt.Println to print the slice [21 22 23 25].
