登录
    Technology changes quickly but people's minds change slowly.

go 语言简单demo

技术宅 破玉 1635次浏览 0个评论

   go 语言简单的demo

package main

import (
	"fmt"
	"bufio"
	"os"
	"strings"
)

func main() {
	// 从命令行获取输入
	inputReader:=bufio.NewReader(os.Stdin)
	fmt.Println("please input your name:")
	input,err:=inputReader.ReadString('\n')
	if err!=nil{
		fmt.Printf("an error occured:%s\n",err)
		// 出现异常退出
		os.Exit(0)
	}else{
		name:=input[:len(input)-1]
		fmt.Printf("Hello %s,what can i do for you?\n",name)
	}
	for{
		input,err:=inputReader.ReadString('\n')
		if err!=nil{
			fmt.Printf("an error occured:%s\n",err)
			// 出现异常退出
			continue
		}else{
			input:=input[:len(input)-1]
			input=strings.ToLower(input)
			switch input {
			case "":
				continue
			case "nothing","bye":
				fmt.Println("Bye!")
				os.Exit(0)
			default:
				if strings.Contains(input,"?"){
					input=strings.Replace(input,"?","!",1)
					input=strings.Replace(input,"吗","",1)
					fmt.Println(input)
				}else{
					fmt.Println("Sorry, I didn't catch you. Your question is too hard!!!")
				}
			}

		}
	}

}


华裳绕指柔, 版权所有丨如未注明 , 均为原创|转载请注明go 语言简单demo
喜欢 (1)
发表我的评论
取消评论
表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址