0
0
Goprogramming~15 mins

Basic input concepts in Go - Mini Project: Build & Apply

Choose your learning style9 modes available
Basic Input Concepts in Go
๐Ÿ“– Scenario: You are creating a simple Go program that asks a user for their name and age, then greets them with this information.
๐ŸŽฏ Goal: Build a Go program that reads user input for name and age, then prints a greeting message including both.
๐Ÿ“‹ What You'll Learn
Use fmt.Scanln to read user input
Store the name in a variable called name
Store the age in a variable called age
Print the greeting using fmt.Printf with the exact format
๐Ÿ’ก Why This Matters
๐ŸŒ Real World
Reading user input is essential for interactive command-line tools and simple programs that need user data.
๐Ÿ’ผ Career
Understanding basic input/output in Go is important for backend development, scripting, and building CLI applications.
Progress0 / 4 steps
1
Create variables for user input
Declare a variable called name of type string and a variable called age of type int.
Go
Need a hint?

Use var keyword to declare variables with their types.

2
Read user input for name and age
Use fmt.Scanln to read input from the user into the variables name and age.
Go
Need a hint?

Use fmt.Scanln(&variable) to read input into variables.

3
Create greeting message
Use fmt.Printf to print the message: Hello, [name]! You are [age] years old. replacing [name] and [age] with the variables name and age.
Go
Need a hint?

Use %s for strings and %d for integers in fmt.Printf.

4
Run the program and see the output
Run the program and enter John for the name and 30 for the age. The program should print: Hello, John! You are 30 years old.
Go
Need a hint?

Make sure to enter the exact inputs when running the program.