Exercise · Interfaces · lesson 10 of 10
Exercise: describe a value
Write a function func describe(v any) string that describes a value by its type. For an int it returns "int " followed by the number, and for a bool it returns "bool " followed by true or false. For a string the result is "string of N bytes", where N is the length of the string in bytes.
describe(42)→"int 42"describe("мир")→"string of 6 bytes"describe(3.5)→"unknown"
Constraints: the string may be empty, and then N is 0; for nil the function returns "nil", and for any other type, such as float64, it returns "unknown".
Do not add extra imports unless the task says so explicitly.
Subscribe to take the course
The course is free. Sign in with Telegram and subscribe to the channel to open every lesson.