Menu
Coddy logo textTech

Recap - Input and Output

Part of the Fundamentals section of Coddy's GO journey. Lesson 33 of 109.

challenge icon

Challenge

Easy

In 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 %s for strings
  • Use %d for integers
  • Use %.2f for floating-point numbers with 2 decimal places
  • Use %t for boolean values
  • Use %T to display the type of a variable

Make sure each output line ends with a newline character (\n).

The exact text is Active: true.

The exact text is Age: 5 years.

The exact text is Name: Gopher.

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 the name line from the instructions, using the name variable and the %s format specifier
  
  // TODO: Use fmt.Printf to print the age line from the instructions, 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 the active line from the instructions, 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

Practice on your own: Online Go compiler