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
1.2k views
in Data Manipulation Through SQL by (49.1k points)
closed by

Create an interactive program to accept the details from user and store it in a csv file using Python for the following table?

1 Answer

+1 vote
by (54.8k points)
selected by
 
Best answer

Database name;- DB1

Table name : Customer

cust_Id Cust_Name Address Phone_no City
C008 Sandeep 14/1 Pritam Pura 41206819 Delhi
C010 Anurag Basu 15A,Park Road 612819121 Kolkata
C012 Hrithik 7/2 Vasant Nagar 26121949 Delhi

import sqlite3 import io import csv

d = open(‘c:/pyprg/sql.csv’ , ‘w’) c = csv.writer(d) 

connection = sqlite3.connect(“dbl.db”)

cursor = connection.cursor( )

cursor.execute(“create table customer(cust_Id, 

cust_Name, Address, Phone_no, City)”) 

print(“Enter 3 customer details:”)

print(“Enter 3 customer Id :”)

cid = [int(input( )) for i in range (3)]

print(“Enter customer names :”)

cname = [input( ) for i in range (3)]

print(“Enter their Address:”)

add = [input( ) for i in range (3)]

int(“Enter their phone numbers:”)

ph = [int(input( )) for i in range (3)]

print(“Enter their cities:”)

city = [input( ) for i in range (3)]

n = len(cname)

for i in range (n):

cursor.execute(“insert into customer values (?,?,?,?,?)” , (cid[i], cname[i], add[i], ph[i], city[i])) 

cursor.execute(“Select * from customer “)

co = [i[0] for i in cursor, description] c.writerow(co) 

data = cursor. fetchall( )

for item in data:

c.writerow(item)

– d.close( )

with open(‘c:/pyprg/sql.csv’ , “r” , newline = None) as fd:

for line in fd:

line = line.replace(“\n” , ” “)

print(line)

cursor. close( )

connection. close( )

OUTPUT:

Enter 3 customer details:

Enter 3 customer Id:

C008

C010

C012

Enter customer names:

Sandeep

Anurag Basu

Hrithik

Enter their Address:

14/1 Pritam Pura

15/A, Park Road

7/2 Vasant Nagar

Enter their Phone Numbers: 

41206819 

61281921 

26121949 

Enter their cities: 

Delhi 

Kolkata 

Delhi 

Displaying Data:

(‘cust_Id’ , ‘cust_Name’ , ‘Address’ , ‘Phone_no’, ‘city’)

(C008, ‘Sandeep’ , ’14/1 Pritampura’ , ‘41206819’ , ’Delhi’)

(C010, ‘Anurag Basu’ , ’15A, Park Road’ , ’61281921’ , ’Kolkata’)

(C012, ’Hrithik’ , ’7/2 Vasant Nagar’ , ’26121949’ , ’Delhi’)

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.

...