Converting boolean values to strings

Report a typo

Patrick has created a small Go program to test out his knowledge on parsing data from strings. His program takes as input a bool type value, then converts it to a string, and finally, prints both the converted type and its value.

When he tried to execute the program, he got an error because he used an incorrect function from the strconv package.

Please help Patrick fix his code by implementing the correct function that allows you to convert a bool type value to a string value, and then print both the converted type and its value.

Sample Input 1:

true

Sample Output 1:

string true
Write a program in Go
package main

import (
"fmt"
"strconv"
)

func main() {
// Do not change or delete these two lines below!
var myBool bool
fmt.Scanln(&myBool)

// What is the correct function to convert bool types to strings?
val := strconv.ParseBool(myBool)

// This line prints the converted type and its value, do not delete it!
fmt.Printf("%T %s", val, val)
}
___

Create a free account to access the full topic