Use app×
Join Bloom Tuition
One on One Online Tuition
JEE MAIN 2025 Foundation Course
NEET 2025 Foundation Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
0 votes
935 views
in Python and CSV Files by (54.8k points)
reopened by

Write a python program to get data at runtime and write it in a csv file?

Please log in or register to answer this question.

1 Answer

+1 vote
by (49.1k points)

import csv

with open(‘c:\ \pyprg\ \chl3\\dynamicfile.csv’ , ‘w’) as f: 

w = csv. writer (f)

ans= ’y’

while (ans= = ’y’):

name= input(“Name?: “)

date = input(“Date of birth: “)

place = input(“Place: “) w.writerow([name, date, place])

ans=input(“Do you want to enter more y/n?: “) 

F=open(‘c:\ \pyprg\ \chl3\\dynamiefde.csv, ’r’)

reader = csv.reader(F)

for row in reader:

print(row)

F.close( )

OUTPUT

Name?: Nivethitha

Date of birth: 12/12/2001

Place: Chennai

Do you want to enter more y/n?: y

Name?: Leena

Date of birth: 15/10/2001

Place: Nagercoil

Do you want to enter more y/n?: y

Name?: Padma

Date of birth: 18/08/2001

Place: Kumbakonam

Do you want to enter more y/n?: n

[‘Nivethitha’ , ’12/12/2001′, ‘Chennai’] [ ]

[’Leena’ , ’15/10/2001′, ‘Nagercoil’] [ ]

[‘Padma’ , ’18/08/2001′, ‘Kumbakonam’]

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

...