Copyproject1Day06

我小时候看过一部电影,应该是最早的一部关于机器人的电影,我记得那个机器人说的一句话,至今我都觉得很好玩:“我能把一个苹果吃很久,我能把一个苹果吃很久..........."

我觉得我能把几十行代码写好几天 innocent

  • 今天是实现了 学生信息 保存功能

  • 插入(添加)学生信息功能

    #This is a funtion ,its funtion is save the information in the file 
    def save(student):
        #try:
        students_txt=open(filename,"a")#  Additional mode 
        #except Exception as e:
        students_txt=open(filename,"w")# If not exist create one 
        for info in student :
            students_txt.write(str(info)+"\n")  # Press the line and add the line
        students_txt.close()
    print("The funtion save")
    

问题是 异常处理的 except 在这里报错, 不知道为什么。我用的是Annaconda.明天我去研究一下

# this part is funtion insert
def insert ():
    studentList=[]
    mark=True
    while mark:
        id=input("Please input your ID:")
        if not id :
            break
        name = input("Please input your name:")
        if not name:
            break
        try :
            english = input("Please input your english grade:")
            Python  = input("Please input your python grade :")
            C = input("Please input your C language grade:") 
        except :
            print("Sorry,your input is invalid,reinter please !")
            continue 
        # save the students information to the dictionary
        student = {"id":id,"name":name,"english":english,"Python":Python,"C":C}
        studentList.append(student)
        if inputMark == "y":
            mark =True
        else:
            mark = False
    save(studentList)
    print("Finished therecording of students' information!")

睡觉

python-3·python-2
129 views
Comments
登录后评论
Sign In
·

你不要浪费时间 对自己狠一点嘛