如何添加到TXT文件

2024-09-25 00:36:08 发布

您现在位置:Python中文网/ 问答频道 /正文

你好,我有一个名为学生.txt内有姓名。你知道吗

Buddy Mike Freshman 3.00
Allen Hood Sophmore 3.45
Dave Beck Freshman 3.00
Jose Sanford Sophmore 3.45
Juan Castro Freshman 3.00

我想将用户输入的信息添加到现有文件students中,并用新内容打印出来。你知道吗

def add_Student():
    myNames = []
    Name = input("Enter First and Last Name of Sudent: ")
    Status = input("Enter Status of Stdent: ")
    GPA = input("Enter Students GPA: ")
    newStudent = Student.Student(Name, Status, GPA )

    print("Student' Name: ",newStudent.getName())
    print("Student' Status: ",newStudent.getStatus())
    print("Student' GPA: ",newStudent.getGPA())

Tags: ofnametxtinputstatusstudent学生姓名