class Item(object): 

    def __init__(self, ID, name, price, stock ): 
        self.ID = ID 
        self.name = name 
        self.price = price 
        self.stock = stock 

    def getID(self): 
        return self.ID 

    def getName(self): 
        return self.name 

    def getPrice(self): 
        return self._price 

    def setPrice(self,value): 
        self.price = value 

    def buyStock(self, howMany): 
        self.stock += howMany 

    def sellStock(self, howMany): 
        if howMany <= self.stock: 
            self.stock -= howMany 
            return True 
        else: 
            return False 

    def __str__(self): 
        return str(self.ID) + " " + self.name + " $%0.2f " %self.price + str(self.stock)

Ive started this program but i need this program to use the Item class but provide the same functionality as it already does. Then it needs to save and then load it capabilities.

Please Help

Recommended Answers

All 7 Replies

Hi,

I think there was no answer because this is not very understandable. First of all, this isn't a program, there is no main, we don't really know what you want to do with this class, what would this 'same functionality ' be?

Please explain further....

there is no main

Python does not require a "main" function. I would be better the say that no instance of the class has been called/created. This is a link to the instant python tutorial which includes classes http://hetland.org/writing/instant-python.html If you copied this program and want to modify it, I would suggest you find some other way as it is obviously more than you understand about Python. On the other hand, if you do make some changes and get an error, feel free to post back for assistance.

That's what I obviously meant about the main, obvious for the two of us maybe not for ITgirl2010....

True. And someone should have caught this thread earlier and asked some questions about what the OP wanted to do, as the program basically returns variables only. Oh well.

Python does not require a "main" function. I would be better the say that no instance of the class has been called/created. This is a link to the instant python tutorial which includes classes http://hetland.org/writing/instant-python.html If you copied this program and want to modify it, I would suggest you find some other way as it is obviously more than you understand about Python. On the other hand, if you do make some changes and get an error, feel free to post back for assistance.

Gosh, I learned new thing from that myself:

You can use back quotes instead of repr

>>> a='45'
>>> print a
45
>>> print `a`
'45'
>>> print repr(a)
'45'
>>> a=45
>>> print `a`
45
>>> print repr(a)
45
>>>

Backquotes are supposed to be eliminated in Python 3, but who knows for sure.

So it seems, after prove in Python 3.1. Also looks very good way of confusing others and yourself in future to use code with some quotes and backquotes here and there. I do love backquotes in Unix/Linux command line though :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.