gpt4 book ai didi

python - 如何从父类获取方法值?运行此代码时出现错误

转载 作者:行者123 更新时间:2023-12-01 06:28:08 25 4
gpt4 key购买 nike

class V_Tangensial():
pi = 3.14

def __init__(self, n=1480, db=220):
self.n = n
self.db = db

def v_tangensial(self):
v = (self.pi * self.n * self.db) / 60000
self.v += v
print(f"Kecepatan Tangensial = {v}")

class Kd(V_Tangensial):

def __init__(self, yh=1, yg=1.5, ys=0.9, ko=0.33, yv=0, kd=0):
v = super(Kd, self).v_tangensial(self)

def Nilai_KD(self):
yv = 0.7 + (0.6/(1+(8/v)**2))

最佳答案

您缺少 super().__init__ 调用。执行此操作后,v_tangensial 将位于 Kd 实例中,即 self

class V_Tangensial():
pi = 3.14

def __init__(self, n=1480, db=220):
self.n = n
self.db = db
self.v = 0

def v_tangensial(self):
v = (self.pi * self.n * self.db) / 60000
self.v += v
print(f"Kecepatan Tangensial = {v}")


class Kd(V_Tangensial):

def __init__(self, yh=1, yg=1.5, ys=0.9, ko=0.33, yv=0, kd=0):
super().__init__(kd)
self.v_tangensial()

def Nilai_KD(self):
yv = 0.7 + (0.6/(1+(8/self.v)**2))

关于python - 如何从父类获取方法值?运行此代码时出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60025984/

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