Computer Project Body
Computer Project Body
import pickle
s={}
f=open('element.dat','wb')
ans='y'
print(s)
pickle.dump(s,f)
f.close()
def display():
import pickle
s={}
f=open('element.dat','rb')
print('\n')
try:
while True:
s=pickle.load(f)
print(s)
except EOFError:
f.close()
def search():
import pickle
s={}
found='f'
f=open('element.dat','rb')
ano=int(input("Enter atomic number of the element to be searched:"))
print('\n')
try:
while True:
s=pickle.load(f)
found='t'
print(s)
except EOFError:
if found=='t':
print("found")
print('\n')
else:
print('not found')
print('\n')
f.close()
def update():
import pickle
s={}
found="f"
f=open('element.dat','rb+')
print('\n')
try:
while True:
pos=f.tell()
s=pickle.load(f)
found='t'
print(s)
print(s)
f.seek(pos)
pickle.dump(s,f)
break
except EOFError:
if found=='t':
print("found")
print('\n')
else:
print("not found")
print('\n')
f.close()
def delete():
import pickle
import os
s={}
found='f'
f=open('element.dat','rb+')
f1=open('element1.dat','wb+')
print('\n')
try:
while True:
s=pickle.load(f)
pickle.dump(s,f1)
else:
found='t'
except EOFError:
if found=='t':
print('\n')
else:
print('\n')
f.close()
f1.close()
os.remove('element.dat')
os.rename('element1.dat','element.dat')
ch=1
while ch:
if ch==1:
add()
elif ch==2:
display()
elif ch==3:
search()
elif ch==4:
update()
elif ch==5:
delete()
else:
ch==6
break
Output
Output 1
Elements record /n
2. To display th records
4. To update a record
5. To delete a record
6. To exit
{'Name of the element': 'Sodium', 'Symbol of the element': 'Na', 'Block and group of the
element': 552.9, 'Atomic number of the element': 11, 'Atomic weight of the element': 22.989,
'Density of the element': 0.971, 'Atomic radius of the element': 186.0, 'Melting point of the
element': 97.8, 'Boiling point of the element': 552.9, 'Year of discovery of the element': 1807}
Output 2
Do you want to add more records(y/n) n
Elements record /n
2. To display th records
4. To update a record
5. To delete a record
6. To exit
{'Name of the element': 'Sodium', 'Symbol of the element': 'Na', 'Block and group of the
element': 552.9, 'Atomic number of the element': 11, 'Atomic weight of the element': 22.989,
'Density of the element': 0.971, 'Atomic radius of the element': 186.0, 'Melting point of the
element': 97.8, 'Boiling point of the element': 552.9, 'Year of discovery of the element': 1807}
found
Output 3
Elements record /n
2. To display th records
4. To update a record
5. To delete a record
6. To exit
{'Name of the element': 'Sodium', 'Symbol of the element': 'Na', 'Block and group of the
element': 552.9, 'Atomic number of the element': 11, 'Atomic weight of the element': 22.989,
'Density of the element': 0.971, 'Atomic radius of the element': 186.0, 'Melting point of the
element': 97.8, 'Boiling point of the element': 552.9, 'Year of discovery of the element': 1807}
{'Name of the element': 'Aluminium', 'Symbol of the element': 'Al', 'Block and group of the
element': 2467.0, 'Atomic number of the element': 13, 'Atomic weight of the element':
26.982, 'Density of the element': 2.702, 'Atomic radius of the element': 143.0, 'Melting point
of the element': 660.37, 'Boiling point of the element': 2467.0, 'Year of discovery of the
element': 1825}
Output 4
Elements record /n
2. To display th records
4. To update a record
5. To delete a record
6. To exit