1 Star 0 Fork 0

张先森 / gotcha

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
main.go 905 Bytes
一键复制 编辑 原始数据 按行查看 历史
Zhang Chengdong 提交于 2020-07-15 16:13 . fix typo
package main
import (
"encoding/csv"
"fmt"
"math/rand"
"os"
"strings"
"time"
)
func main() {
records := ParseCsv()
if len(records) == 0 {
fmt.Println("Pokemon names not found, quit now.")
os.Exit(1)
}
fmt.Printf("\nSuccessfully loaded %d pokemon names!\n\n", len(records))
cmd := "n"
r := rand.New(rand.NewSource(time.Now().Unix()))
idx := r.Intn(len(records))
for {
rec := records[idx]
fmt.Printf("Gotcha! %s ( %s / %s ) at %s!\n\n", rec[1], rec[2], rec[3], rec[0])
fmt.Print("Need another one? [y/N] ")
fmt.Scanf("%s", &cmd)
if strings.ToLower(cmd) == "y" {
idx = r.Intn(len(records))
cmd = "n"
fmt.Println("")
} else {
break
}
}
fmt.Println("Bye!")
}
func ParseCsv() [][]string {
fi, err := os.Open("./name.csv")
if err != nil {
panic(err)
}
r := csv.NewReader(fi)
records, err := r.ReadAll()
if err != nil {
panic(err)
}
return records
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/bejames/gotcha.git
git@gitee.com:bejames/gotcha.git
bejames
gotcha
gotcha
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891