Class - 12 CBSE Computer Science Important File Handling Questions 2025
Write code to open the file in the previous question and print it in the following form:
Name : <name> Phone: <phone number>
Python Data Handling
2 Likes
Answer
Let the file "contacts.csv" include the following sample data:
Aniketh,9876546707
Sanjeeth,8976548689
Amrutha,6786778908
import csv
with open("con.csv", "r") as file:
csvreader = csv.reader(file)
for row in csvreader:
if row:
name = row[0]
phone = row[1]
print("Name:", name,"\t\t" "Phone:", phone)
Output
Name: Aniketh Phone: 7868478767
Name: Sanjeeth Phone: 6766474789
Name: Amrutha Phone: 8749374678
Answered By
2 Likes