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).

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