0% found this document useful (0 votes)
3 views9 pages

Practical

The document contains multiple Python scripts that manage student marks, stock inventory, and sales records using both pickle and CSV formats. It includes functions for accepting data, backing up records, updating stock prices, calculating total sales, and analyzing text files for word counts and character types. Additionally, it interacts with a MySQL database to perform queries on an inventory table.

Uploaded by

rohini
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views9 pages

Practical

The document contains multiple Python scripts that manage student marks, stock inventory, and sales records using both pickle and CSV formats. It includes functions for accepting data, backing up records, updating stock prices, calculating total sales, and analyzing text files for word counts and character types. Additionally, it interacts with a MySQL database to perform queries on an inventory table.

Uploaded by

rohini
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

import pickle

def Accept():
f=open("[Link]","wb")
while(True):
name=input("Enter Student Name:")
mark1=int(input("Enter Subject1 marks:"))
mark2=int(input("Enter Subject2 marks:"))
mark3=int(input("Enter Subject3 marks:"))
mark4=int(input("Enter Subject4 marks:"))
mark5=int(input("Enter Subject5 marks:"))
avg=(mark1+mark2+mark3+mark4+mark5)/5
lst=[name,mark1,mark2,mark3,mark4,mark5,avg]
[Link](lst,f)
ch=input("Do you want to add another record (Y/N):")
if ch in "Nn":
break
[Link]()
return

def Backup():
f=open("[Link]","rb")
studentLst=[]
classavg=0
try:
marksavg=0
while(True):
lst=[Link](f)
[Link](lst)
marksavg=marksavg+lst[6]
except:
[Link]()
classavg=marksavg/len(studentLst)

f=open("[Link]","wb")
fr=open("[Link]","wb")
for student in studentLst:
if student[6]>classavg:
[Link](student,f)
else:
[Link](student,fr)

[Link]()
[Link]()
return

Accept()
Backup()
#Output
f=open("[Link]","rb")
fr=open("[Link]","rb")
print("[Link]")
try:
while(True):
lst=[Link](f)
print(lst)
except:
[Link]()
print("[Link]")
try:
while(True):
lst=[Link](fr)
print(lst)
except:
[Link]()

import pickle

def Stock():
f=open("[Link]","wb")
while True:
ICode=input("Enter product Code:")
Name=input("Enter Product Name:")
Company=input("Enter Company Name:")
DoP=input("Enter Date of Purchase:")
Price=float(input("Enter Price:"))
lst=[ICode,Name,Company,DoP,Price]
[Link](lst,f)
ch=input("Do you want to add another record (Y/N):")
if ch in "Nn":
break
[Link]()
return

def Update(company,disc):
f=open("[Link]","rb")
StockLst=[]
try:
while(True):
lst=[Link](f)
if lst[2]==company:
lst[4]=lst[4]-lst[4]*disc/100
[Link](lst)
except:
[Link]()
f=open("[Link]","wb")
for lst in StockLst:
[Link](lst,f)
[Link]()
return

Stock()
company=input("Enter the Company Name:")
disc=int(input("Enter Discount Percentage:"))
Update(company,disc)

#Output
f=open("[Link]","rb")
try:
while(True):
lst=[Link](f)
print(lst)
except:
[Link]()

import pickle

def Store():
f=open("[Link]","wb")
while True:
Product_ID=input("Enter product ID:")
Product_Name=input("Enter Product Name:")
Quantity_Sold=int(input("Enter Quantity Sold:"))
Unit_Price=float(input("Enter Unit Price:"))
lst=[Product_ID,Product_Name,Quantity_Sold,Unit_Price]
[Link](lst,f)
ch=input("Do you want to add another record (Y/N):")
if ch in "Nn":
break
[Link]()
return

def CalcTotSales(ProductName):
f=open("[Link]","rb")
TotalSales=0
ProductFound=False
try:
while(True):
lst=[Link](f)
if(lst[1]==ProductName) :
TotalSales=TotalSales+lst[2]
ProductFound=True
except:
[Link]()
if ProductFound:
print("Total Sales of",ProductName," : ",TotalSales)
else:
print("Product Not Found")
return

Store()
ProductName=input("Enter the Product Name:")
CalcTotSales(ProductName)

#Output
f=open("[Link]","rb")
try:
while(True):
lst=[Link](f)
print(lst)
except:
[Link]()

import csv

def Accept():
f=open("[Link]","w",newline="")
writer=[Link](f)
while(True):
name=input("Enter Student Name:")
mark1=int(input("Enter Subject1 marks:"))
mark2=int(input("Enter Subject2 marks:"))
mark3=int(input("Enter Subject3 marks:"))
mark4=int(input("Enter Subject4 marks:"))
mark5=int(input("Enter Subject5 marks:"))
avg=(mark1+mark2+mark3+mark4+mark5)/5
lst=[name,mark1,mark2,mark3,mark4,mark5,avg]
[Link](lst)
ch=input("Do you want to add another record (Y/N):")
if ch in "Nn":
break
[Link]()
return

def Backup():
f=open("[Link]","r")
reader=[Link](f)
studentLst=[]
classavg=0
marksavg=0
for rec in reader:
[Link](rec)
marksavg=marksavg+float(rec[6])
classavg=marksavg/len(studentLst)
print(classavg)
[Link]()

f=open("[Link]","w",newline="")
writer=[Link](f)
frem=open("[Link]","w",newline="")
writerrem=[Link](frem)
for student in studentLst:
if float(student[6])>classavg:
[Link](student)
else:
[Link](student)

[Link]()
[Link]()
return

Accept()
Backup()

import csv

def Stock():
f=open("[Link]","w",newline="")
writer=[Link](f)
while True:
ICode=input("Enter product Code:")
Name=input("Enter Product Name:")
Company=input("Enter Company Name:")
DoP=input("Enter Date of Purchase:")
Price=float(input("Enter Price:"))
lst=[ICode,Name,Company,DoP,Price]
[Link](lst)
ch=input("Do you want to add another record (Y/N):")
if ch in "Nn":
break
[Link]()
return

def Update(company,disc):
f=open("[Link]","r")
reader=[Link](f)
StockLst=[]
for lst in reader:
if lst[2]==company:
lst[4]=float(lst[4])-float(lst[4])*disc/100
[Link](lst)
[Link]()
f=open("[Link]","w",newline="")
writer=[Link](f)
for lst in StockLst:
[Link](lst)
[Link]()
return

Stock()
company=input("Enter the Company Name:")
disc=int(input("Enter Discount Percentage:"))
Update(company,disc)

import csv

def Store():
f=open("[Link]","w",newline="")
writer=[Link](f)
while True:
Product_ID=input("Enter product ID:")
Product_Name=input("Enter Product Name:")
Quantity_Sold=int(input("Enter Quantity Sold:"))
Unit_Price=float(input("Enter Unit Price:"))
lst=[Product_ID,Product_Name,Quantity_Sold,Unit_Price]
[Link](lst)
ch=input("Do you want to add another record (Y/N):")
if ch in "Nn":
break
[Link]()
return

def CalcTotSales(ProductName):
f=open("[Link]","r")
reader=[Link](f)
TotalSales=0
ProductFound=False
for lst in reader:
if(lst[1]==ProductName) :
TotalSales=TotalSales+int(lst[2])
ProductFound=True
[Link]()
if ProductFound:
print("Total Sales of",ProductName," : ",TotalSales)
else:
print("Product Not Found")
return

Store()
ProductName=input("Enter the Product Name:")
CalcTotSales(ProductName)
f=open("[Link]","r")
fw=open("[Link]","w")
lines=[Link]()
for line in lines:
revline=""
for ch in line:
revline=ch+revline
[Link](revline)
[Link]()
[Link]()

f=open("[Link]","r")
text=[Link]()
wordlst=[Link]()
worddict={}
for word in wordlst:
count=[Link](word,0)
worddict[word]=count+1
print(worddict)
countlst=list([Link]())
print(countlst)
[Link](reverse=True)
print(countlst)
#Top five words
top5list=[]
for freq in countlst:
for key in worddict :
if worddict[key]==freq and key not in top5list:
[Link](key)
if len(top5list)==5 :
break
if len(top5list)==5 :
break
print(top5list)

def vowelWord(fn):
f=open(fn,"r")
text=[Link]()
wordlist=[Link]()
uppercasecount=0
lowercasecount=0
for word in wordlist:
if word[0] in 'aeiouAEIOU':
print(word)
if word[0].isupper():
uppercasecount=uppercasecount+1
if word[0].islower():
lowercasecount=lowercasecount+1
print("Number of uppercase words:",uppercasecount)
print("Number of lowercase words:",lowercasecount)
return

def consonantlines():
f=open("[Link]","r")
try:
while True:
text=[Link]()
if text[0] not in 'aeiouAEIOU' :
print(text)
except:
[Link]()

vowelWord("[Link]")
consonantlines()

import [Link]

mydb=[Link](user="root",host="localhost",passwd="password",
database="school")
mycursor=[Link]()
query1="select * from Inventory where cost between 1000 and 1500"
[Link](query1)
myrecords=[Link]()
for rec in myrecords:
print(rec)
query2="select min(Qty),max(Qty) from Inventory"
[Link](query2)
myrecords=[Link]()
for rec in myrecords:
print("Min Qty:",rec[0])
print("Max Qty:",rec[1])
query3="update Inventory set cost=cost+cost*5/100"
[Link](query3)
query4="select * from Inventory"
[Link](query4)
myrecords=[Link]()
for rec in myrecords:
print(rec)
query5="select avg(cost),sum(cost) from Inventory"
[Link](query5)
myrecords=[Link]()
for rec in myrecords:
print("Average Price:",rec[0])
print("Total Price:",rec[1])
def Push_Element():
for i in L:
if i[1]>150:
[Link](i)
x=len(Product)
for j in range(x-1,-1,-1):
print(Product[j])
return

def Pop_Element():
while True:
if len(Product)==0:
print("Stack Empty")
break
else:
print([Link]())
return

L=[("Laptop",90000),("Mobile",30000),("Pen",50),("Headphones",1500),("Marker",150)]
Product=[]
Push_Element()
Pop_Element()

f=open("[Link]","r")
text=[Link]()
numcount=0
vowelcount=0
consonantcount=0
sum=0
for ch in text:
if [Link]():
numcount=numcount+1
sum=sum+int(ch)
elif ch in 'aeiouAEIOU':
vowelcount=vowelcount+1
else:
consonantcount=consonantcount+1
print("numcount:",numcount)
print("Sum:",sum)
print("vowelcount:",vowelcount)
print("consonantcount:",consonantcount)
[Link]()

You might also like