0% found this document useful (0 votes)
11 views

Computer Project Source Code

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

Computer Project Source Code

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

def add():

import pickle

s={}

f=open('element.dat','wb')

ans='y'

while ans== 'y':

n= input("Enter element's name:")

c= input("Enter elemnets symbol:")

b= input("Enter element's block and group:")

a= int(input("Enter atomic number of the element:"))

w= float(input("Enter atomic weight of the element:"))

d= float(input("Enter density(g/ml) of the element:"))

r= float(input("Enter atomic radius of the element:"))

m= float(input("Enter melting point(c) of the element:"))

b= float(input("Enter boiling point of the element:"))

y= int(input("Enter year of discovery of the element:"))

s['Name of the element']=n

s['Symbol of the element']=c

s['Block and group of the element']=b

s['Atomic number of the element']=a

s['Atomic weight of the element']=w

s['Density of the element']=d

s['Atomic radius of the element']=r

s['Melting point of the element']=m

s['Boiling point of the element']=b


s['Year of discovery of the element']=y

print(s)

pickle.dump(s,f)

ans= input("Do you want to add more records(y/n)")

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)

if s['Atomic number of the element']==ano:

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')

ano= int(input("Enter atomic number of the element to be updated:"))

try:

while True:

pos=f.tell()
s=pickle.load(f)

if s['Atomic number of the element']==ano:

found='t'

print(s)

n= input("Enter element's name:")

c= input("Enter elemnets symbol:")

b= input("Enter element's block and group:")

a= int(input("Enter atomic number of the element:"))

w= float(input("Enter atomic weight of the element:"))

d= float(input("Enter density(g/ml) of the element:"))

r= float(input("Enter atomic radius of the element:"))

m= float(input("Enter melting point(c) of the element:"))

b= float(input("Enter boiling point of the element:"))

y= int(input("Enter year of discovery of the element:"))

s['Name of the element']=n

s['Symbol of the element']=c

s['Block and group of the element']=b

s['Atomic number of the element']=a

s['Atomic weight of the element']=w

s['Density of the element']=d

s['Atomic radius of the element']=r

s['Melting point of the element']=m

s['Boiling point of the element']=b

s['Year of discovery of the element']=y

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')

ano=int(input("Enter atomic number to be deleted:"))

try:

while True:

s=pickle.load(f)

if s['Atomic number of the element']!=ano:


pickle.dump(s,f1)

else:

found='t'

except EOFError:

if found=='t':

print("found and deleted")

print('\n')

else:

print("Record not found and hence can't be deleted")

print('\n')

f.close()

f1.close()

os.remove('element.dat')

os.rename('element1.dat','element.dat')

ch=1

while ch:

print("Elements record /n")

print("1. To add an element's record")

print("2. To display the records")

print("3. To search for a record")

print("4. To update a record")

print("5. To delete a record")

print("6. To exit")

ch= int(input("Enter your choice 1-6:"))


if ch==1:

print("Add new record")

add()

elif ch==2:

print("Display all records")

display()

elif ch==3:

search()

elif ch==4:

update()

elif ch==5:

delete()

else:

ch==6

print("To exit \n")

break

You might also like