0
0
Goprogramming~10 mins

Why input and output are required in Go - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to read a number from the user.

Go
var num int
fmt.Scanln([1])
Drag options to blanks, or click blank then click option'
Anum&
Bnum
C*num
D&num
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Passing the variable without & causes runtime error.
Using *num is invalid syntax for input.
2fill in blank
medium

Complete the code to print the value of num.

Go
fmt.Println([1])
Drag options to blanks, or click blank then click option'
Anum&
Bnum
C*num
D&num
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using &num prints the memory address, not the value.
Using *num causes error unless num is a pointer.
3fill in blank
hard

Fix the error in reading input into variable x.

Go
var x int
fmt.Scanln([1])
Drag options to blanks, or click blank then click option'
A&x
Bx&
C*x
Dx
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Passing x instead of &x causes input to fail.
Using *x is invalid because x is not a pointer.
4fill in blank
hard

Fill both blanks to create a program that reads and prints a string.

Go
var input string
fmt.Scanln([1])
fmt.Println([2])
Drag options to blanks, or click blank then click option'
A&input
Binput
Cinput&
D*input
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using input instead of &input for reading input.
Using &input when printing prints the address.
5fill in blank
hard

Fill all three blanks to read two integers and print their sum.

Go
var a, b int
fmt.Scanln([1], [2])
sum := [3]
fmt.Println(sum)
Drag options to blanks, or click blank then click option'
A&a
B&b
Ca + b
Da - b
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Passing a and b instead of &a and &b to Scanln.
Using subtraction instead of addition for sum.