Golang添加学生成绩管理最low版本
package main import "fmt" func main() { var stu = make(map[int]map[string]string) var istrue = false for true { s1 := ` 1 添加学生成绩 2 查看学生成绩 3 修改学生成绩 4 删除学生成绩 5 退出程序 ` fmt.Println(s1) var sub_stu = make(map[string]string) var choice int fmt.Println("请输入选择:") fmt.Scanln(&choice) switch choice { case 1: // 添加学生成绩 var sid int fmt.Println("请输入学号:") fmt.Scanln(&sid) var name string fmt.Println("请输入姓名:") fmt.Scanln(&name) var english_score string fmt.Println("请输入英语成绩:") fmt.Scanln(&english_score) var chinese_score string fmt.Println("请输入语文成绩:") fmt.Scanln(&chinese_score) var math_score string fmt.Println("请输入数学成绩:") fmt.Scanln(&math_score) sub_stu["name"] = name sub_stu["english_score"] = english_score sub_stu["math_score"] = math_score sub_stu["chinese_score"] = chinese_score stu[sid] = sub_stu case 2: // 查看学生成绩 for k,v := range stu{ fmt.Printf("学号:%d\t姓名:%s\t语文成绩:%s\t数学成绩: %s\t英语成绩:%s\n", k,v["name"], v["chinese_score"], v["math_score"], v["english_score"]) } case 3: // 修改学生成绩 fmt.Println("请输入学生ID:") var sid int fmt.Scanln(&sid) for k,_ := range stu{ if k == sid { var name string fmt.Println("请输入姓名:") fmt.Scanln(&name) var english_score string fmt.Println("请输入英语成绩:") fmt.Scanln(&english_score) var chinese_score string fmt.Println("请输入语文成绩:") fmt.Scanln(&chinese_score) var math_score string fmt.Println("请输入数学成绩:") fmt.Scanln(&math_score) sub_stu["name"] = name sub_stu["english_score"] = english_score sub_stu["math_score"] = math_score sub_stu["chinese_score"] = chinese_score stu[sid] = sub_stu } } case 4: // 删除 fmt.Println("请输入学生ID:") var sid int fmt.Scanln(&sid) for k,_ := range stu{ if k == sid { delete(stu,sid) } } case 5: // 退出程序 fmt.Println("退出程序") istrue = true //break } if istrue { break } } }
关注微信公众号:搜索 "IT渣女talks"
We are down, but not beaten. tested but not defeated.