有人可以帮我吗?

问题描述 投票:1回答:1

我不明白为什么我的代码不加-25并将math_obj1计数为0。而且我的sqrt函数遇到问题。它一直说sqrt()接受1个位置参数,但给出了2个。我不明白那是什么意思。有人可以向我澄清吗?非常感谢]]

import math 

import MathLib as math

if __name__ == '__main__':
    math_obj1 = math.MyMathLib(2.0)
    math_obj2 = math.MyMathLib(-0.5)
    math_obj3 = math.MyMathLib(0.0) # this should give 0.0

   print("Math obj1 value = ",math_obj1.get_curr_value() )
   print("Math obj2 value = ",math_obj2.get_curr_value() )
   print("Math obj3 value = ",math_obj3.get_curr_value() )

import MathLib as math



if __name__ == '__main__':
    math_obj1 = math.MyMathLib(25.0)

    print("Math obj1 value = ",math_obj1.get_curr_value() )

    math_obj1.add(25.0)
    print("Math obj1 value = ",math_obj1.get_curr_value() )

    math_obj1.add(-25.0)
    math_obj1.sqrt('y')
    assert (math_obj1.get_curr_value() == 5.0)
    print("Math obj1 value = ",math_obj1.get_curr_value() )


class MyMathLib:
    def __init__(self = math_obj, y = math_obj):
        self.y = y



    def add(self, y):
        return 'self' + 'y'




def mult(self, y):
    #return self.x*y
    return self * y



def divid(self, y):
        #return self.x/y
    if (self != 0):
        return self/y
    else:
        return y




def sequence_sum(self, sequence_list):
    return sum(sequence_list)
def sqrt(self):
    return math.sqrt(y)

def get_curr_value(self):
     #return self.x
     return self.y

我不明白为什么我的代码不加-25并将math_obj1计数为0。而且我的sqrt函数遇到问题。它一直说sqrt()接受1个位置参数,但给出了2个。我...

python math sqrt
1个回答
0
投票

因为您的add

© www.soinside.com 2019 - 2024. All rights reserved.