Go follows the printf tradition from the C language. In my opinion, string formatting/interpolation in Go is less elegant than Python's f-strings, unfortunately.
These following "formatting verbs" work with the formatting functions above:
The %v variant prints any value in a default format. It can be used as a catchall.
s := fmt.Sprintf("I am %v years old", 10)
// I am 10 years old
s := fmt.Sprintf("I am %v years old", "way too many")
// I am way too many years old
If you want to print in a more specific way, you can use the following formatting verbs:
s := fmt.Sprintf("I am %s years old", "way too many")
// I am way too many years old
s := fmt.Sprintf("I am %d years old", 10)
// I am 10 years old
s := fmt.Sprintf("I am %f years old", 10.523)
// I am 10.523000 years old
// The ".2" rounds the number to 2 decimal places
s := fmt.Sprintf("I am %.2f years old", 10.523)
// I am 10.52 years old
If you're interested in all the formatting options, you can look at the fmt package's docs.
Create a new variable called msg on line 9 and use the appropriate formatting function to return a string that contains following:
Hi NAME, your open rate is OPENRATE percentNEWLINE
NAME with the variable name,OPENRATE with the variable openRate rounded to the nearest "tenths" place, e.g 10.523 should be rounded down to 10.5NEWLINE with the newline \n escape sequence.For example, with the inputs "Jimmy McGill" and 2.5, the expected output would be:
Hi Jimmy McGill, your open rate is 2.5 percent