Go Back   CodingForums.com > :: Server side development > Other server side languages/ issues > Python

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-07-2012, 01:15 PM   PM User | #1
hans_cellc
New Coder

 
Join Date: Oct 2011
Posts: 92
Thanks: 38
Thanked 0 Times in 0 Posts
hans_cellc is an unknown quantity at this point
Method to accept arguments

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__


Code:
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()
hans_cellc is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:51 PM.


Advertisement
Log in to turn off these ads.