亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

求解單項和多項式 Python 類

求解單項和多項式 Python 類

慕森王 2022-05-24 10:55:04
我是第一次嘗試類,我想創建一個程序,要求用戶輸入 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()
查看完整描述

1 回答

?
慕運維8079593

TA貢獻1876條經驗 獲得超5個贊

我看到的問題是函數的輸入。您不需要 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()


查看完整回答
反對 回復 2022-05-24
  • 1 回答
  • 0 關注
  • 104 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號