class menu:
def __init__(self,name,price):
self.name = name
self.price = price
if __name__ == '__main__':
print "The content assigned to the union separately:\n"
dish = menu("Sweet and Sour Chicken",9.95)
print "Dish Name: ",dish.name
print "Dish Price: ",dish.price
class employee:
def __init__(self,start_year,dpt_code,id_number):
self.start_year = start_year
self.dpt_code = dpt_code
self.id_number = id_number
if __name__ == '__main__':
info = employee(1997,8,1234)
print "Start Year: ",info.start_year,"\n"
print "Dpt. Code: ",info.dpt_code,"\n"
print "ID Number: ",info.id_number,"\n"
import sys
class u:
def __init__(self,x,y):
self.x = x
self.y = y
class s:
def __init__(self,x,y):
self.x = x
self.y = y
if __name__ == '__main__':
a_union = u(10,20)
a_struct = s(10,20)
#print "The size of double: ",sys.getsizeof(double),"byte\n" Double is not in python
print "The size of int: ",sys.getsizeof(int),"byte\n"
print "The size of union: ",sys.getsizeof(a_union),"byte\n"
print "The size of struct: ",sys.getsizeof(a_struct),"byte\n"
class u:
ch = [0, 0]
num = 0
def UnionInitialize(val):
val.ch[0] = 'H'
val.ch[1] = 'I'
return val.ch
if __name__ == '__main__':
val = u()
x = UnionInitialize(val)
print "The two characters held by the union:\n"
print x[0],"\n"
print x[1],"\n"
class survey:
def __init__(self,name,c_d_p,age,hour_per_week):
self.name = name
self.c_d_p = c_d_p
self.age = age
self.hour_per_week = hour_per_week
class provider:
def __init__(self,cable_company,dish_company):
self.cable_company = cable_company
self.dish_company = dish_company
def DataEnter(ptr):
is_yes = raw_input("Are you using cable at home? (Yes or No): ")
if is_yes == 'Y' or is_yes == 'y':
ptr.provider.cable_company = raw_input("Enter the cable company name: ")
ptr.c_d_p = 'c'
else:
is_yes = raw_input("Are you using a satellite dish? (Yes or No): ")
if is_yes == 'Y' or is_yes == 'y':
ptr.provider.dish_company = raw_input("Enter the satellite dish company name: ")
ptr.c_d_p = 'd'
else:
ptr.c_d_p = 'p'
ptr.name = raw_input("Please enter your name: ")
ptr.age = int(raw_input("Your age : "))
ptr.hour_per_week = int(raw_input("How many hours you spend on watching TV per week: "))
def DataDisplay(ptr):
print "\nHere’s what you’ve entered:\n"
print "Name: ",ptr.name,"\n"
print "Age: ",ptr.age,"\n"
print "Hour per week: ",ptr.hour_per_week,"\n"
if ptr.c_d_p == 'c':
print "Your cable company is: ",ptr.provider.cable_company,"\n"
elif ptr.c_d_p == 'd':
print "Your satellite dish company is: ",ptr.provider.dish_company,"\n"
else:
print "You don’t have cable or a satellite dish.\n"
print "\nThanks and Bye!\n"
if __name__ == '__main__':
tv = survey("","","","")
DataEnter(tv)
DataDisplay(tv)
class bit_field:
def __init__(self,cable,dish):
self.cable = cable
self.dish = dish
cable = 1
dish = 1
class survey:
def __init__(self,name,age,hour_per_week):
self.name = name
self.age = age
self.hour_per_week = hour_per_week
c_d = bit_field("","")
class provider:
def __init__(self,cable_company,dish_company):
self.cable_company = cable_company
self.dish_company = dish_company
def DataEnter(ptr):
is_yes = raw_input("Are you using cable at home? (Yes or No): ")
if is_yes == 'Y' or is_yes == 'y':
ptr.provider.cable_company = raw_input("Enter the cable company name: ")
ptr.c_d.cable = 1
ptr.c_d.dish = 0
else:
is_yes = raw_input("Are you using a satellite dish? (Yes or No): ")
if is_yes == 'Y' or is_yes == 'y':
ptr.provider.dish_company = raw_input("Enter the satellite dish company name: ")
ptr.c_d.cable = 0
ptr.c_d.dish = 1
else:
ptr.c_d.cable = 0
ptr.c_d.dish = 0
ptr.name = raw_input("Please enter your name: ")
ptr.age = int(raw_input("Your age : "))
ptr.hour_per_week = int(raw_input("How many hours you spend on watching TV per week: "))
def DataDisplay(ptr):
print "\nHere’s what you’ve entered:\n"
print "Name: ",ptr.name,"\n"
print "Age: ",ptr.age,"\n"
print "Hour per week: ",ptr.hour_per_week,"\n"
if ptr.c_d.cable and not ptr.c_d.dish:
print "Your cable company is: ",ptr.provider.cable_company,"\n"
elif not ptr.c_d.cable and ptr.c_d.dish:
print "Your satellite dish company is: ",ptr.provider.dish_company,"\n"
else:
print "You don’t have cable or a satellite dish.\n"
print "\nThanks and Bye!\n"
if __name__ == '__main__':
tv = survey("","","")
DataEnter(tv)
DataDisplay(tv)