CBSE Class 12 Computer Science Question 98 of 136

Data File Handling — Question 37

Back to all questions
37
Question

Question 37

Write a program to add two more employees' details (empno, ename, salary, designation) to the file "emp.txt" already stored in disk.

Answer

Let the file "emp.txt" include the following sample text:

1001, Ankit Singh, 50000, Manager
1002, Neha Patel, 45000, Developer
file = open("emp.txt", "a")
file.write("1003, Manoj Tiwari, 48000, Analyst\n")
file.write("1004, Aarti Gupta, 52000, Engineer\n")

The file "emp.txt" include the following text:

1001, Ankit Singh, 50000, Manager
1002, Neha Patel, 45000, Developer
1003, Manoj Tiwari, 48000, Analyst
1004, Aarti Gupta, 52000, Engineer