gpt4 book ai didi

php - 对象存储的创建方法

转载 作者:太空宇宙 更新时间:2023-11-03 21:33:52 25 4
gpt4 key购买 nike

创建一个代表商店的对象。让初始化方法获取商店的平方英尺。创建一个可以计算商店电力成本的方法

class Store:
DOLLARS_PER_KWH = 0.15
KWH_PER_SQUARE_FOOTAGE_PER_HOUR = 0.19

def __init__(self):
self.square_footage = square_footage

def cost(self, DOLLARS_PER_KWH, KWH_PER_SQUARE_FOOTAGE_PER_HOUR):
self.electrical_costs = self * DOLLARS_PER_KWH * KWH_PER_SQUARE_FOOTAGE_PER_HOUR
print(f' Electrical costs are {self.electrical_costs} dollars.')

我在 init 调用中收到类型错误,以及带有成本的名称错误,这里有什么问题?请帮助编辑我的代码!

最佳答案

 class Store:
DOLLARS_PER_KWH = 0.15
KWH_PER_SQUARE_FOOTAGE_PER_HOUR = 0.19

def __init__(self,square_footage):
self.square_footage = square_footage
Store.DOLLARS_PER_KWH
Store.KWH_PER_SQUARE_FOOTAGE_PER_HOUR

def cost(self):
self.electrical_costs = self.square_footage *Store.DOLLARS_PER_KWH *Store.KWH_PER_SQUARE_FOOTAGE_PER_HOUR
print ("Electrical costs are $%.2f." % (self.electrical_costs))

emp1 = Store(10)
emp1.cost()

enter image description here

关于php - 对象存储的创建方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53358724/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com