name=[]
price=[]
pages=[]
for i in range(3):
name.append("\0")
price.append(0)
pages.append(0)
print "Enter names,prices and no. of pages of 3 books\n"
for i in range(0,3,1):
name[i]=raw_input()
price[i]=eval(raw_input())
pages[i]=eval(raw_input())
print "\nAnd this is what you entered\n"
for i in range(0,3,1):
print "%c %f %d\n" % (name[i],price[i],pages[i])
class book: #YOU CAN ALSO USE CTYPES FOR IMPLEMENTING STRUCTURES
def __init__(self, **kwds):
self.__dict__.update(kwds)
b1=book()
b2=book()
b3=book()
print "Enter names,prices & no. of pages of 3 books\n"
b1.name=raw_input()
b1.price=eval(raw_input())
b1.pages=eval(raw_input())
b2.name=raw_input()
b2.price=eval(raw_input())
b2.pages=eval(raw_input())
b3.name=raw_input()
b3.price=eval(raw_input())
b3.pages=eval(raw_input())
print "And this is what you entered\n"
print "%c %f %d\n" % (b1.name,b1.price,b1.pages)
print "%c %f %d\n" % (b2.name,b2.price,b2.pages)
print "%c %f %d\n" % (b3.name,b3.price,b3.pages)
class book():
def __init__(self,**kwds):
self.__dict__.update(kwds)
b1=book(name='B',price=130.00,pages=550)
print "Address of name=%u\n" % (id(b1.name))
print "Address of price=%u\n" % (id(b1.price))
print "Address of pages=%u\n" % (id(b1.pages))
def linkfloat():
a=0
b=id(a) #cause emulator to be linked
class book():
def __init__(self,**kwds):
self.__dict__.update(kwds)
b=[]
for i in range(3):
b.append(0) #setting initial value as zero
for i in range(0,3,1):
b[i]=book()
for i in range(0,3,1):
print "Enter name price and pages"
b[i].name=raw_input()
b[i].price=eval(raw_input())
b[i].pages=eval(raw_input())
for i in range(0,3,1):
print "%c %f %d\n" % (b[i].name,b[i].price,b[i].pages)
class employee():
def __init__(self,**kwds):
self.__dict__.update(kwds)
e1=employee(name="Sanjay",age=30,salary=5500.50)
e2=employee()
e3=employee()
#piece-meal copying
import copy
e2.name=copy.copy(e1.name)
e2.age=e1.age
e2.salary=e1.salary
#copying all elements at one go
e3=e2
print "%s %d %f\n" % (e1.name,e1.age,e1.salary)
print "%s %d %f\n" % (e2.name,e2.age,e2.salary)
print "%s %d %f\n" % (e3.name,e3.age,e3.salary)
class address():
def __init__(self, **kwds):
self.__dict__.update(kwds)
class emp():
def __init__(self, **kwds):
self.__dict__.update(kwds)
a = address(phone="531046", city="nagpur", pin=10)
e = emp(name="jeru", address=a)
print "name=%s phone=%s\n" % (e.name,e.address.phone)
print "city=%s pin=%d\n" % (e.address.city,e.address.pin)
class book():
def __init__(self, **kwds):
self.__dict__.update(kwds)
def display(s,t,n):
print "%s %s %d\n" % (s,t,n)
b1=book(name="Let us C",author="YPK",callno=101)
display(b1.name,b1.author,b1.callno)
class book():
def __init__(self, **kwds):
self.__dict__.update(kwds)
def display(b):
print "%s %s %d\n" % (b.name,b.author,b.callno)
b1=book(name="Let us C",author="YPK",callno=101)
display(b1)
class book():
def __init__(self, **kwds):
self.__dict__.update(kwds)
b1=book(name="Let us C",author="YPK",callno=101)
ptr=book()
ptr=b1
print "%s %s %d\n" % (b1.name,b1.author,b1.callno)
print "%s %s %d\n" % (ptr.name,ptr.author,ptr.callno)
class book():
def __init__(self, **kwds):
self.__dict__.update(kwds)
def display(b):
print "%s %s %d\n" % (b.name,b.author,b.callno)
b1=book(name="Let us C",author="YPK",callno=101)
display(b1)
class emp():
def __init__(self, **kwds):
self.__dict__.update(kwds)
e=emp(a=0,ch='\0',s=0.0)
print "%u %u %u\n" % (id(e.a),id(e.ch),id(e.s))
class emp():
def __init__(self,a,ch,s): #Structure without using dictionary
self.a=a
self.ch=ch
self.s=s
e=emp(a=0,ch='\0',s=0.0)
print "%u %u %u\n" % (id(e.a),id(e.ch),id(e.s))