0

Hello so I have this text filed named students.txt with names inside.

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

I want to add the information the user entered to the existing file students and have it print out with the new contents.

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())
metmirr
  • 4,234
  • 2
  • 21
  • 34
Supreme
  • 17
  • 1
  • 6

1 Answers1

0

To append data to a file you open it with the option "a":

with open("students.txt","a") as textfile:
    print(Name,Status,GPA,file=textfile)
Marvo
  • 523
  • 7
  • 16