Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/278.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
求解单项式和多项式Python类_Python_Python 3.x - Fatal编程技术网

求解单项式和多项式Python类

求解单项式和多项式Python类,python,python-3.x,Python,Python 3.x,我第一次用类进行实验,我想创建一个程序,要求用户输入a、b和c,然后为打印语句中所述的方程式形式求解x。但是,我在类中遇到了问题,给了我一个错误,我没有使用类中的变量,缺少5个位置参数。任何帮助都将是惊人的,非常感谢 class EquationSolver: def MonomialSolver(self,a,b,c,x): a = input("Enter Input for a:") b = input("Enter Input for b:")

我第一次用类进行实验,我想创建一个程序,要求用户输入a、b和c,然后为打印语句中所述的方程式形式求解x。但是,我在类中遇到了问题,给了我一个错误,我没有使用类中的变量,缺少5个位置参数。任何帮助都将是惊人的,非常感谢

class EquationSolver:
    def MonomialSolver(self,a,b,c,x):
        a = input("Enter Input for a:")
        b = input("Enter Input for b:")
        c = input("Enter input for c:")
        x = (c+b)/a
        print("For the equation in the format ax-b=c, with your values chosen x must equal", x)
    def PolynomialSolver(self,a,b,c,x):
        a = input("Enter Input for a:")
        b = input("Enter Input for b:")
        c = input("Enter input for c:")
        x = (c^2 + b) / a
        print("For the equation in the format sqrt(ax+b) = c, with your values chosen x must equal", x)
    MonomialSolver()
    PolynomialSolver()

我看到的问题是函数的输入。您不需要self参数或任何其他参数。这些函数应该在循环之外运行。编辑的版本应循环如下内容:

class EquationSolver:
    def MonomialSolver():
        # Uses float() to turn input to a number
        a = float(input("Enter Input for a:"))
        b = float(input("Enter Input for b:"))
        c = float(input("Enter input for c:"))
        x = (c+b)/a
        print("For the equation in the format ax-b=c, with your values chosen x must equal", x)
    def PolynomialSolver():
        a = float(input("Enter Input for a:"))
        b = float(input("Enter Input for b:"))
        c = float(input("Enter input for c:"))
        x = (c^2 + b) / a
        print("For the equation in the format sqrt(ax+b) = c, with your values chosen x must equal", x)
EquationSolver.MonomialSolver()
EquationSolver.PolynomialSolver()