Asdf
Asdf
# List-Program No : L4-P1
# Developed By : SAI GAMBHIR 12J 2024-2025
# Date : 29-August-2024
# --------------------------------------------------------------#
import pickle
def Enrol():
with open("CANDIDATE.DAT",'wb') as F:
while True:
CNum=int(input("Candidate No.: "))
CName=input("Candidate Name: ")
Sc=float(input("Score: "))
pickle.dump([CNum,CName,Sc],F)
Q=input("More Details(Y/N)? ")
if Q in 'Nn':
break
def GetPass():
try:
with open("CANDIDATE.DAT",'rb') as F:
while True:
try:
X=pickle.load(F)
if X[2]>=50:
print(X)
except:
break
except FileNotFoundError:
print("No File!")
def ShowAll():
try:
with open("CANDIDATE.DAT",'rb') as F:
while True:
try:
Y=pickle.load(F)
print(Y)
except:
break
except FileNotFoundError:
print("No File!")
def AverageScore():
try:
S,C=0,0
with open("CANDIDATE.DAT",'rb') as F:
while True:
try:
Z=pickle.load(F)
S+=Z[2]
C+=1
except:
break
print("Average Score:",S/C)
except FileNotFoundError:
print("No File!")
while True:
OP=input("E=Enrol G=GetPass S=ShowAll A=AverageScore Q=Quit: ")
if OP in ['e','E']:
Enrol()
elif OP in ['g','G']:
GetPass()
elif OP in ['s','S']:
ShowAll()
elif OP in ['a','A']:
AverageScore()
else:
break
'''
E=Enrol G=GetPass S=ShowAll A=AverageScore Q=Quit: E
Candidate No.: 112590
Candidate Name: Jack
Score: 50.6
More Details(Y/N)? Y
Candidate No.: 391734
Candidate Name: Tony
Score: 90.8
More Details(Y/N)? Y
Candidate No.: 569012
Candidate Name: Remy
Score: 20.5
More Details(Y/N)? Y
Candidate No.: 221198
Candidate Name: Liam
Score: 87.2
More Details(Y/N)? Y
Candidate No.: 901234
Candidate Name: Wendy
Score: 37.8
More Details(Y/N)? N
E=Enrol G=GetPass S=ShowAll A=AverageScore Q=Quit: G
[112590, 'Jack', 50.6]
[391734, 'Tony', 90.8]
[221198, 'Liam', 87.2]
E=Enrol G=GetPass S=ShowAll A=AverageScore Q=Quit: S
[112590, 'Jack', 50.6]
[391734, 'Tony', 90.8]
[569012, 'Remy', 20.5]
[221198, 'Liam', 87.2]
[901234, 'Wendy', 37.8]
E=Enrol G=GetPass S=ShowAll A=AverageScore Q=Quit: A
Average Score: 57.38000000000001
E=Enrol G=GetPass S=ShowAll A=AverageScore Q=Quit: Q
'''
import pickle
def Register():
with open("ACCOUNTS.DAT",'wb') as F:
L=[]
while True:
Ano=int(input("Account Number: "))
Nm=input("Name: ")
Bal=float(input("Balance: $"))
L.append([Ano,Nm,Bal])
C=input("More(Y/N)? ")
if C in 'Nn':
break
pickle.dump(L,F)
def Transact():
try:
with open("ACCOUNTS.DAT",'rb+') as F:
R=pickle.load(F)
for I in R:
print(I)
Q=input("Deposit(D) or Withdraw(W)? ")
if Q in 'Dd':
Amt=float(input("Amount: $"))
I[2]+=Amt
else:
Amt=float(input("Amount: $"))
I[2]-=Amt
F.seek(0)
pickle.dump(R,F)
except FileNotFoundError:
print("No File!")
def DisplayAll():
try:
with open("ACCOUNTS.DAT",'rb') as F:
S=pickle.load(F)
for J in S:
print(J)
except FileNotFoundError:
print("No File!")
def BankBalance():
try:
S=0
with open("ACCOUNTS.DAT",'rb') as F:
L=pickle.load(F)
for I in L:
S+=I[2]
print("Sum of Balance of all Account Holders =",S)
except FileNotFoundError:
print("No File!")
while True:
Q=input("R=Resgister T=Transact D=DisplayAll B=BankBalance Q=Quit: ")
if Q in 'Rr':
Register()
elif Q in 'Tt':
Transact()
elif Q in 'Dd':
DisplayAll()
elif Q in 'Bb':
BankBalance()
else:
break
'''
R=Resgister T=Transact D=DisplayAll B=BankBalance Q=Quit: R
Account Number: 102938475601
Name: John
Balance: $50670
More(Y/N)? Y
Account Number: 098765432138
Name: Oliver
Balance: $200460
More(Y/N)? Y
Account Number: 123456789056
Name: Ryan
Balance: $1230400
More(Y/N)? N
R=Resgister T=Transact D=DisplayAll B=BankBalance Q=Quit: T
[102938475601, 'John', 50670.0]
Deposit(D) or Withdraw(W)? D
Amount: $500
[98765432138, 'Oliver', 200460.0]
Deposit(D) or Withdraw(W)? D
Amount: $700
[123456789056, 'Ryan', 1230400.0]
Deposit(D) or Withdraw(W)? W
Amount: $100
R=Resgister T=Transact D=DisplayAll B=BankBalance Q=Quit: D
[102938475601, 'John', 51170.0]
[98765432138, 'Oliver', 201160.0]
[123456789056, 'Ryan', 1230300.0]
R=Resgister T=Transact D=DisplayAll B=BankBalance Q=Quit: B
Sum of Balance of all Account Holders = 1482630.0
R=Resgister T=Transact D=DisplayAll B=BankBalance Q=Quit: Q
'''
import pickle
def Register():
with open("EMPLOYEES.DAT",'wb') as F:
R=[]
while True:
Empno=int(input("Employee No.: "))
Ename=input("Employee Name: ")
Dept=input("Department: ")
Sal=float(input("Salary: $"))
R.append([Empno,Ename,Dept,Sal])
C=input("More Details(Y/N)? ")
if C in 'Nn':
break
pickle.dump(R,F)
def GetAccounts():
try:
with open('EMPLOYEES.DAT','rb') as F:
R=pickle.load(F)
for I in R:
if I[2].upper()=='ACCOUNTS':
print(I)
except FileNotFoundError:
print("No File!")
def ShowAll():
try:
with open('EMPLOYEES.DAT','rb') as F:
R=pickle.load(F)
for J in R:
print(J)
except FileNotFoundError:
print('No File!')
def IncreaseSal():
try:
with open("EMPLOYEES.DAT",'rb+') as F:
R=pickle.load(F)
for I in R:
if I[3]<50000:
I[3]+=10000
F.seek(0)
pickle.dump(R,F)
except FileNotFoundError:
print("No File!")
while True:
Q=input("R=Register G=GetAccounts S=ShowAll I=IncreaseSal Q=Quit: ")
if Q in 'Rr':
Register()
elif Q in 'Gg':
GetAccounts()
elif Q in 'Ss':
ShowAll()
elif Q in 'Ii':
IncreaseSal()
else:
break
'''
R=Register G=GetAccounts S=ShowAll I=IncreaseSal Q=Quit: R
Employee No.: 113925
Employee Name: Kelly
Department: Accounts
Salary: $35000
More Details(Y/N)? Y
Employee No.: 104723
Employee Name: Peter
Department: Marketing
Salary: $45000
More Details(Y/N)? Y
Employee No.: 284693
Employee Name: Jacob
Department: Analytics
Salary: $80000
More Details(Y/N)? Y
Employee No.: 393792
Employee Name: Andrew
Department: Accounts
Salary: $35000
More Details(Y/N)? N
R=Register G=GetAccounts S=ShowAll I=IncreaseSal Q=Quit: G
[113925, 'Kelly', 'Accounts', 35000.0]
[393792, 'Andrew', 'Accounts', 35000.0]
R=Register G=GetAccounts S=ShowAll I=IncreaseSal Q=Quit: S
[113925, 'Kelly', 'Accounts', 35000.0]
[104723, 'Peter', 'Marketing', 45000.0]
[284693, 'Jacob', 'Analytics', 80000.0]
[393792, 'Andrew', 'Accounts', 35000.0]
R=Register G=GetAccounts S=ShowAll I=IncreaseSal Q=Quit: I
R=Register G=GetAccounts S=ShowAll I=IncreaseSal Q=Quit: S
[113925, 'Kelly', 'Accounts', 45000.0]
[104723, 'Peter', 'Marketing', 55000.0]
[284693, 'Jacob', 'Analytics', 80000.0]
[393792, 'Andrew', 'Accounts', 45000.0]
R=Register G=GetAccounts S=ShowAll I=IncreaseSal Q=Quit: Q
'''
import pickle
def AddItem():
with open("ITEMS.DAT",'wb') as F:
L=[]
while True:
Itemno=int(input("Item Number: "))
Iname=input("Item Name: ")
Qty=int(input("Quntity: "))
Price=float(input("Price: $"))
L.append([Itemno,Iname,Qty,Price])
W=input("More Items(Y/N)? ")
if W in 'Nn':
break
pickle.dump(L,F)
def ShowItems(File):
try:
if File.upper()=='ITEMS.DAT':
with open(File.upper(),'rb') as F:
T=pickle.load(F)
for J in T:
print(J)
elif File.upper()=='LOWSTOCK.DAT':
with open(File.upper(),'rb') as F:
U=pickle.load(F)
for K in U:
print(K)
except FileNotFoundError:
print("No File!")
def CreateDemand():
try:
with open('ITEMS.DAT','rb') as F1:
F2=open('LOWSTOCK.DAT','wb')
M=[]
P=pickle.load(F1)
for I in P:
if I[2]<10:
M.append(I)
pickle.dump(M,F2)
F2.close()
except FileNotFoundError:
print('No File!')
while True:
Q=input('A=AddItem S=ShowItems C=CreateDemand Q=Quit: ')
if Q.upper()=='A':
AddItem()
elif Q.upper()=='S':
E=input('File Name: ')
ShowItems(E)
elif Q.upper()=='C':
CreateDemand()
else:
break
'''
A=AddItem S=ShowItems C=CreateDemand Q=Quit: A
Item Number: 0123498
Item Name: Water Bottle
Quntity: 4
Price: $70
More Items(Y/N)? Y
Item Number: 902276
Item Name: Lunch Box
Quntity: 11
Price: $89
More Items(Y/N)? Y
Item Number: 682457
Item Name: Notebook
Quntity: 20
Price: $90
More Items(Y/N)? Y
Item Number: 681360
Item Name: Pencil
Quntity: 7
Price: $23
More Items(Y/N)? N
A=AddItem S=ShowItems C=CreateDemand Q=Quit: S
File Name: ITEMS.DAT
[123498, 'Water Bottle', 4, 70.0]
[902276, 'Lunch Box', 11, 89.0]
[682457, 'Notebook', 20, 90.0]
[681360, 'Pencil', 7, 23.0]
A=AddItem S=ShowItems C=CreateDemand Q=Quit: C
A=AddItem S=ShowItems C=CreateDemand Q=Quit: S
File Name: LOWSTOCK.DAT
[123498, 'Water Bottle', 4, 70.0]
[681360, 'Pencil', 7, 23.0]
A=AddItem S=ShowItems C=CreateDemand Q=Quit: Q
'''
import pickle
M=['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec']
def AddBook():
with open('BOOKS.DAT','wb') as F:
L=[]
while True:
Bno=int(input('Book Number: '))
Bname=input('Book Name: ')
Author=input('Author Name: ')
Price=float(input('Price of Book: $'))
print(M)
MMM=input('Month: ')
DD=input('Date: ')
YYYY=input('Year: ')
PD=DD+'-'+MMM+'-'+YYYY
L.append([Bno,Bname,Author,Price,PD])
C=input('More Books(Y/N)? ')
if C in 'Nn':
break
pickle.dump(L,F)
def ShowBooks():
try:
with open('BOOKS.DAT','rb') as F:
P=pickle.load(F)
for I in P:
print(I)
except FileNotFoundError:
print('No File!')
def DeleteOld():
try:
with open('BOOKS.DAT','rb+') as F:
R=pickle.load(F)
L=[]
for I in R:
if I[4][-8:-5] not in M[:5] and int(I[4][-4:])>=2024:
L.append(I)
F.seek(0)
pickle.dump(L,F)
except FileNotFoundError:
print('No File!')
while True:
Q=input("A=AddBook S=ShowBooks D=DeleteOld Q=Quit: ")
if Q.upper()=='A':
AddBook()
elif Q.upper()=='S':
ShowBooks()
elif Q.upper()=='D':
DeleteOld()
else:
break
'''
A=AddBook S=ShowBooks D=DeleteOld Q=Quit: A
Book Number: 356734
Book Name: A Tale of Two Cities
Author Name: Charles Dickens
Price of Book: $40
['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov',
'Dec']
Month: Apr
Date: 24
Year: 2024
More Books(Y/N)? Y
Book Number: 454760
Book Name: The Three Musketeers
Author Name: Alexandre Dumas
Price of Book: $39
['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov',
'Dec']
Month: Sep
Date: 27
Year: 2024
More Books(Y/N)? Y
Book Number: 676721
Book Name: It Ends With Us
Author Name: Colleen Hoover
Price of Book: $46
['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov',
'Dec']
Month: Mar
Date: 30
Year: 2024
More Books(Y/N)? Y
Book Number: 129043
Book Name: 1984
Author Name: George Orwell
Price of Book: $57
['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov',
'Dec']
Month: Jun
Date: 1
Year: 2024
More Books(Y/N)? N
A=AddBook S=ShowBooks D=DeleteOld Q=Quit: S
[356734, 'A Tale of Two Cities', 'Charles Dickens', 40.0, '24-Apr-2024']
[454760, 'The Three Musketeers', 'Alexandre Dumas', 39.0, '27-Sep-2024']
[676721, 'It Ends With Us', 'Colleen Hoover', 46.0, '30-Mar-2024']
[129043, '1984', 'George Orwell', 57.0, '1-Jun-2024']
A=AddBook S=ShowBooks D=DeleteOld Q=Quit: D
A=AddBook S=ShowBooks D=DeleteOld Q=Quit: S
[454760, 'The Three Musketeers', 'Alexandre Dumas', 39.0, '27-Sep-2024']
A=AddBook S=ShowBooks D=DeleteOld Q=Quit:
=============== RESTART: C:\Users\Sang\Cloud Storage\CLassXII.py
===============
A=AddBook S=ShowBooks D=DeleteOld Q=Quit: A
Book Number: 356734
Book Name: A Tale of Two Cities
Author Name: Charles Dickens
Price of Book: $40
['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov',
'Dec']
Month: Apr
Date: 24
Year: 2024
More Books(Y/N)? Y
Book Number: 454760
Book Name: The Three Musketeers
Author Name: Alexandre Dumas
Price of Book: $39
['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov',
'Dec']
Month: Sep
Date: 27
Year: 2024
More Books(Y/N)? Y
Book Number: 129043
Book Name: 1984
Author Name: George Orwell
Price of Book: $57
['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov',
'Dec']
Month: Jun
Date: 1
Year: 2024
More Books(Y/N)? Y
Book Number: 676721
Book Name: It Ends With Us
Author Name: Colleen Hoover
Price of Book: $46
['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov',
'Dec']
Month: Mar
Date: 30
Year: 2024
More Books(Y/N)? N
A=AddBook S=ShowBooks D=DeleteOld Q=Quit: S
[356734, 'A Tale of Two Cities', 'Charles Dickens', 40.0, '24-Apr-2024']
[454760, ' The Three Musketeers', 'Alexandre Dumas', 39.0, '27-Sep-2024']
[129043, '1984', 'George Orwell', 57.0, '1-Jun-2024']
[676721, 'It Ends With Us', 'Colleen Hoover', 46.0, '30-Mar-2024']
A=AddBook S=ShowBooks D=DeleteOld Q=Quit: D
A=AddBook S=ShowBooks D=DeleteOld Q=Quit: S
[454760, ' The Three Musketeers', 'Alexandre Dumas', 39.0, '27-Sep-2024']
[129043, '1984', 'George Orwell', 57.0, '1-Jun-2024']
A=AddBook S=ShowBooks D=DeleteOld Q=Quit: Q
'''