2016 Update
This commit is contained in:
parent
948b86eafa
commit
dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions
33
Task/Topic-variable/Go/topic-variable.go
Normal file
33
Task/Topic-variable/Go/topic-variable.go
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"math"
|
||||
"os"
|
||||
"strconv"
|
||||
"text/template"
|
||||
)
|
||||
|
||||
func sqr(x string) string {
|
||||
f, err := strconv.ParseFloat(x, 64)
|
||||
if err != nil {
|
||||
return "NA"
|
||||
}
|
||||
return strconv.FormatFloat(f*f, 'f', -1, 64)
|
||||
}
|
||||
|
||||
func sqrt(x string) string {
|
||||
f, err := strconv.ParseFloat(x, 64)
|
||||
if err != nil {
|
||||
return "NA"
|
||||
}
|
||||
return strconv.FormatFloat(math.Sqrt(f), 'f', -1, 64)
|
||||
}
|
||||
|
||||
func main() {
|
||||
f := template.FuncMap{"sqr": sqr, "sqrt": sqrt}
|
||||
t := template.Must(template.New("").Funcs(f).Parse(`. = {{.}}
|
||||
square: {{sqr .}}
|
||||
square root: {{sqrt .}}
|
||||
`))
|
||||
t.Execute(os.Stdout, "3")
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue