Comp
Comp
Comp
mycon=sqltor.connect(host='localhost',user='root',password='akash@123',database='factory')
if mycon.is_connected:
print('connected to mysql')
cursor=mycon.cursor()
data=cursor.fetchall()
r=cursor.rowcount
print(r)
for i in data:
print(i)
2. Write a program to make a dictionary of product Sold to
the customer with its price and print it.
x={}
for i in range(8):
x[p]=r
print(x)
f=0
for i in x:
if i==n:
print("found",x[i])
f=1
break
if f==0:
def insert_r():
cursor=my.cursor()
n=input('enter name')
m=int(input('enter marks'))
g=input('enter grade')
s=input('enter section')
cursor.execute(st)
my.commit()
return
def display_r():
cursor=my.cursor()
cursor.execute(st)
data=cursor.fetchall()
for i in data:
print(i)
return
def delete_r():
cursor=my.cursor()
cursor.execute(st)
my.commit()
return
def update_r():
cursor=my.cursor()
cursor.execute(st)
my.commit()
return
def exit_from_d():
my.close()
return
import mysql.connector as s
my=s.connect(host='localhost',user='root',password='akash@123',database='factory')
if my.is_connected():
cursor=my.cursor()
ans='y'
while ans=="y":
print('main menu')
print('1.insert record')
print('2.display record')
print('3.delete record')
print('4.update record')
if c=='1':
insert_r()
elif c=='2':
display_r()
elif c=='3':
delete_r()
elif c=='4':
update_r()
elif c=='5':
exit_from_d()
break
if ans!='y':
my.close()
ans='n'
4. Write a program in python to write some text in text file
akash .txt
f=open("C:\\Users\\Akash\\OneDrive\\Documents\\akash .txt",'a+')
c=f.read()
print(c)
a='1'
while a=='1':
s=input("enter a string")
f.write(s)
import pickle
def write():
f=open("C:\\Users\\Akash\\OneDrive\\Desktop\\Newl.dat",'wb')
l=eval(input("enter a list"))
d=eval(input("enter a dictionary"))
pickle.dump(l,f)
pickle.dump(d,f)
f.close()
def read():
f=open("C:\\Users\\Akash\\OneDrive\\Desktop\\Newl.dat",'rb')
try:
print("record=")
while True:
a=pickle.load(f)
print(a)
except EOFError:
print("program Excuted")
f.close()
while a in ['y','n']:
if a=='y':
write()
else:
read()
import pickle
f=open("C:\\Users\\Akash\\OneDrive\\Desktop\\Newl.dat",'rb+')
d={}
for i in range(5):
pickle.dump(d,f)
try:
print("record of file")
while True:
s=pickle.load(f)
print(s)
except EOFError:
print("program excuted")
f.close()
7. Write a program in python to write student details in the
CSV file new.csv .
import csv
def write():
f=open("C:\\Users\\Akash\\OneDrive\\Documents\\New.csv",'a+',newline='\r\n')
w=csv.writer(f)
w.writerow(['Rollno.','Name','subject','Marks'])
for i in range(n):
r=int(input("enter SR No."))
n=input("enter name")
s=input("enter subject")
m=int(input("enter marks"))
w.writerow([r,n,s,m])
print("data added")
f.close()
def read():
with open("C:\\Users\\Akash\\OneDrive\\Documents\\New.csv",'r',newline='\r\n') as f:
r=csv.reader(f)
for i in r:
print(i)
print("over")
f.close()
a='1'
while a=='1':
if c=='w':
write()
elif c=='r':
read()
else:
break
a=input("enter 1 to continue")
if a not in['1']:
print("wrong choise")