0
0
Goprogramming~10 mins

Basic input concepts in Go - Interactive Code Practice

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

Complete the code to read a string input from the user.

Go
var name string
fmt.Print("Enter your name: ")
fmt.Scanln([1])
fmt.Println("Hello,", name)
Drag options to blanks, or click blank then click option'
A&name
Bname
C*name
Dname&
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Passing the variable without & causes a runtime error.
Using *name is invalid because name is not a pointer.
2fill in blank
medium

Complete the code to read an integer input from the user.

Go
var age int
fmt.Print("Enter your age: ")
fmt.Scanln([1])
fmt.Println("You are", age, "years old")
Drag options to blanks, or click blank then click option'
A&age
B*age
Cage
Dage&
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Passing age without & causes input not to be stored.
Using *age is invalid since age is not a pointer.
3fill in blank
hard

Fix the error in reading a float input from the user.

Go
var price float64
fmt.Print("Enter price: ")
fmt.Scanln([1])
fmt.Printf("Price: %.2f\n", price)
Drag options to blanks, or click blank then click option'
Aprice
Bprice&
C*price
D&price
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Passing price without & causes the value not to be stored.
Using *price is invalid because price is not a pointer.
4fill in blank
hard

Fill both blanks to read two inputs: a string and an integer.

Go
var name string
var age int
fmt.Print("Enter name and age: ")
fmt.Scanln([1], [2])
fmt.Println(name, age)
Drag options to blanks, or click blank then click option'
A&name
Bname
C&age
Dage
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Passing variables without & causes input not to be stored.
Mixing & and non-& variables causes errors.
5fill in blank
hard

Fill all three blanks to read a string, an integer, and a float input.

Go
var name string
var age int
var height float64
fmt.Print("Enter name, age, and height: ")
fmt.Scanln([1], [2], [3])
fmt.Println(name, age, height)
Drag options to blanks, or click blank then click option'
A&name
B&age
C&height
Dheight
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Forgetting & causes input not to be stored.
Passing a variable without & among others causes runtime errors.