Anonymous user
Keyboard input/Obtain a Y or N response: Difference between revisions
Keyboard input/Obtain a Y or N response (view source)
Revision as of 01:38, 18 January 2020
, 4 years ago→{{header|Go}}
m (→{{header|MiniScript}}: added "works with" tag) |
|||
Line 730:
s.Refresh()
s.GetChar()
}</lang>
<lang go>package main
// https://siongui.github.io/2016/04/23/go-read-yes-no-from-console
import (
"fmt"
"strings"
)
func ask() bool {
var s string
fmt.Printf("(y/n): ")
fmt.Scan(&s)
s = strings.TrimSpace(s)
s = strings.ToLower(s)
if s == "y" || s == "yes" {
return true
}
return false
}
func main() {
ans := ask()
if ans {
fmt.Println("yes")
} else {
fmt.Println("no")
}
}</lang>
|