class merchandise:
def __init__(self, item, quantity, cost):
self.__item = item
self.__quantity = quantity
self.__cost = cost
def set_item(self, item):
self.__item = item
def set_quantity(self, quantity):
self.__quantity = quantity
def set_cost(self, cost):
self.__cost = cost
def get_item(self):
return self.__item
def get_quantity(self):
return self.__quantity
def get_cost(self):
return self.__cost
def get_inventory_value(self):
return (format(self.__quantity * self.__cost, '.2f'))
def __str__(self):
for i in merchandise:
print (self.__item+',', self.__quantity,'@ $'+(format (self.__cost,'.2f')))
import merchandise
def main(_):
def make_list():
for count in range (1,3):
merchandise.set_item("hammer")
merchandise.set_quantity(10)
merchandise.set_cost(14.95)
print(hammer)
hardware = float (input ('Enter a new quantity for hardware '))
jewelry = float (input ('Enter a new cost for jewelry '))
hammer = merchandise.merchandise()
stuff = make_list()
print (stuff)
main()
私は何が間違っているのか分かりません。商品にset_itemがありません。私はかなりのことを試してきましたが、これまで何も働いていませんでした。私はここから離れているか、それは何かばかげたことですか?クラス関数を呼び出すPython
あなたがインスタンス化/ – Li357
を初期化する必要があり、別のファイルまたは1つのファイルにクラスとの主ですか?別に、あなたが '商品を輸入する '、'商品 'がモジュールオブジェクトである場合、' merchandise.merchandise'はクラスです。 _Class_には 'set_item'メソッドがありません。一方、_Class instances_は 'set_item'メソッドを持っています。 –