How can i add one value on inside python file?

Dears

i want to add one value through python code to the file that created manually and also add one row
this the question 2- Create a class called students that receives the student id, name and level. This class has two methods; the first one to add one mark to the list of student marks (called add_mark) and the other one to return student’s informamtion (called dump)
3- Write a function called ‘create_student’. This function will receive a file name and an id, then it will read the file and create one student from the c
and this my code?

f = open("/content/Student.txt", “r”)

f.close()

f = open(“Student.txt”, ‘r’)
lines = f.readlines()
for line in lines:
if line == ‘100’:

  print(line)

class student():
def add_mark(self, id, name, level):
f = open(“Student.txt”)
self.id = id
self.name = name
self.level = level
class student():
def dump():
f = open(“Student.txt”)
lines = f.readlines()
for line in lines:
print(line)

Hello, @Nouf5755569, and welcome the the Python Forum!

This topic seems appropraite for posting in the Users category. Perhaps one of the Administrators can move it there.

For us to help, we’ll need to see the format of the Student.txt file. Please copy and post the first three or four lines of the file.

thank you for your reply
this is the data

100, nouf, 7, 80, 605, 90, 60
200, Hassan, 6, 95, 90, 85
300, Asharf, 7, 85, 77, 87, 89, 87

Hello Nouf,

there are several possibilities to add one value - all of them have in common, that you need a list for this - it is explained here :

(I hope this forum does not mind this )

Greetz.

1 Like

Thanks, @nouf5755569.

Your posted code would look better if it were formatted for posting. This would also make it easier for us to copy for testing. To format code, place three backtick marks on a line before it, and three backticks on a line after it. Alternatively, you can select all the code and click the </> button in the toolbar above the editing window.

Have you learned about creating an __init__ method for initializing an instance of a class? It appears that these three lines should be placed in such a method:

self.id = id
self.name = name
self.level = level

In order to get practice writing an __init__ method, could you please create one for the Student class and post it here. After that, we can continue to help with this task.