Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
37
Task/Menu/Go/menu.go
Normal file
37
Task/Menu/Go/menu.go
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func menu(choices []string, prompt string) string {
|
||||
if len(choices) == 0 {
|
||||
return ""
|
||||
}
|
||||
var c int
|
||||
for {
|
||||
fmt.Println("")
|
||||
for i, s := range choices {
|
||||
fmt.Printf("%d. %s\n", i+1, s)
|
||||
}
|
||||
fmt.Print(prompt)
|
||||
_, err := fmt.Scanln(&c)
|
||||
|
||||
if err == nil && c > 0 && c <= len(choices) {
|
||||
break
|
||||
}
|
||||
}
|
||||
return choices[c-1]
|
||||
}
|
||||
|
||||
func main() {
|
||||
pick := menu(nil, "No prompt")
|
||||
fmt.Printf("No choices, result = %q\n", pick)
|
||||
|
||||
choices := []string{
|
||||
"fee fie",
|
||||
"huff and puff",
|
||||
"mirror mirror",
|
||||
"tick tock",
|
||||
}
|
||||
pick = menu(choices, "Enter number: ")
|
||||
fmt.Printf("You picked %q\n", pick)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue