猜数字
package main import ( "fmt" "math/rand" "time" ) func main() { randNum := creatRandNum() randSlice := make([]int, 4) inputSlice := make([]int, 4) famtterNum(randSlice, randNum) fmt.Println(randNum) //打印随机数 var inputNum int for true { fmt.Println("请输入一个四位数:") fmt.Scan(&inputNum) if inputNum > 999 && inputNum < 10000 { famtterNum(inputSlice, inputNum) for i := 0; i < 4; i++ { if randSlice[i] > inputSlice[i] { fmt.Printf("第%d数字小了\n", i+1) } else if randSlice[i] < inputSlice[i] { fmt.Printf("第%d数字大了\n", i+1) } else { fmt.Printf("第%d数字猜对了\n", i+1) } } } } } //生成随机数 func creatRandNum() int { rand