0
0
Goprogramming~15 mins

Why input and output are required in Go - See It in Action

Choose your learning style9 modes available
Why input and output are required
๐Ÿ“– Scenario: Imagine you want to create a simple program that asks a user for their name and then says hello to them. To do this, the program needs to get information from the user (input) and then show a message back (output).
๐ŸŽฏ Goal: Build a small Go program that asks for a user's name and then prints a greeting message using that name.
๐Ÿ“‹ What You'll Learn
Use fmt.Scanln to get input from the user
Use fmt.Println to show output to the user
Store the input in a variable called name
Print a greeting message that includes the name
๐Ÿ’ก Why This Matters
๐ŸŒ Real World
Many programs need to ask users questions and show answers, like calculators, games, or websites.
๐Ÿ’ผ Career
Understanding input and output is a basic skill for any programmer to make interactive applications.
Progress0 / 4 steps
1
Create a variable to store the user's name
Declare a variable called name of type string to hold the user's input.
Go
Need a hint?

Use var name string to create a variable that can hold text.

2
Get the user's name as input
Use fmt.Scanln(&name) to read the user's input and store it in the variable name.
Go
Need a hint?

Use fmt.Scanln(&name) to read what the user types and save it in name.

3
Print a greeting message using the input
Use fmt.Println with a message that says Hello, followed by the value of name.
Go
Need a hint?

Use fmt.Println("Hello,", name) to show the greeting.

4
Run the program and see the output
Run the program. When it asks for input, type GoLearner and press Enter. The program should print Hello, GoLearner.
Go
Need a hint?

Type GoLearner when the program waits for input, then press Enter to see the greeting.