...

Method to accept arguments

hans_cellc
09-07-2012, 01:15 PM
I have the following code, seems to work but my set_data not being used, it is suppose to be the method that accepts the arguments from the __init__


class Cellphone:
#The __init__ method must accept arguments for
#for the manufacturer, model number and retail
#price
def __init__(self, manufact, model, price):
self.manufact = manufact
self.model = model
self.price = price

def set_data(self, new_manufact, new_model, new_price):
if new_manufact == "" or new_model == "" or new_price == "":
print "These fields can not be left empty"
else:
self.manufact = new_manufact
self.model = new_model
self.price = new_price

def get_manufact(self):
return self.manufact
def get_model(self):
return self.model
def get_price(self):
return self.price

def main():
#Get the data
manufacturer = raw_input("Enter the manufacturer: ")
modelnum = raw_input("Enter the model number: ")
retailprice = raw_input("Enter the retail price: ")

#Create an instance of the Cellphone class
myPhone = Cellphone(manufacturer, modelnum, retailprice)
myPhone.set_data(manufacturer, modelnum, retailprice)

#Display the data that was entered
print "\nYour phone's manufacturer is:\t" + myPhone.get_manufact()
print "Your phone's model number is:\t" + myPhone.get_model()
print "Your phone's selling price is:\tR" + myPhone.get_price()

main()



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum