Recap - Input and Output
Part of the Fundamentals section of Coddy's GO journey — lesson 33 of 109.
Challenge
EasyIn this challenge, you'll practice using fmt.Printf to display formatted output with different format specifiers.
Complete the code to display information about a Gopher using the appropriate format specifiers:
- Use
%sfor strings - Use
%dfor integers - Use
%.2ffor floating-point numbers with 2 decimal places - Use
%tfor boolean values - Use
%Tto display the type of a variable
Make sure each output line ends with a newline character (\n).
Try it yourself
package main
import "fmt"
func main() {
// Given variables
name := "Gopher"
age := 5
height := 0.75
isActive := true
// TODO: Use fmt.Printf to print "Name: Gopher" using the name variable and the %s format specifier
// TODO: Use fmt.Printf to print "Age: 5 years" using the age variable and the %d format specifier
// TODO: Use fmt.Printf to print "Height: 0.75 meters" using the height variable and the %.2f format specifier
// TODO: Use fmt.Printf to print "Active: true" using the isActive variable and the %t format specifier
// TODO: Use fmt.Printf to print "Name type: string" using the name variable and the %T format specifier
}All lessons in Fundamentals
4Comparison & Logical Operators
Comparison Operators - Part 1Comparison Operators - Part 2Logical AND OperatorLogical OR OperatorLogical NOT OperatorOperator Precedence BasicsRecap - Making Comparisons7Control Flow: Loops
What The `for` Loop ExplainedFor Loop - BasicFor Loop - Condition OnlyThe `break` KeywordThe `continue` KeywordNested LoopsRecap - Repeating Actions2Variables and Basic Data Types
What is a variableType Inference with `:=`Integers (int)Floating-Point NumbersBooleansStringsZero ValuesConstantsNaming ConventionsRecap - Variables and Types5Basic Input/Output
Formatted OutputFormat VerbsPrinting TypesGetting Basic User InputRecap - Input and Output8Functions
Understanding FunctionsDeclaring a FunctionCalling FunctionsFunction ParametersReturning a Single ValueReturning Multiple ValuesNamed Return ValuesFunction Scope BasicsRecap - Creating Reusable Code3Basic Operators
Arithmetic OperatorsDivision OperatorThe Modulo OperatorAssignment OperatorAugmented Assignment OperatorsIncrement and DecrementRecap - Calculations6Control Flow: Conditionals
The `if` StatementThe `else` KeywordThe `else if` KeywordVariable Shadowing in `if`Initializing VariablesThe `switch` StatementSwitch with ExpressionsSwitch without ExpressionThe `fallthrough` KeywordRecap - Making Decisions