我是任何編程語言的新手,但是目前我正在嘗試創建一個程式,該程式將根據輸入計算用戶的納稅狀況。
我遇到的問題是,當我呼叫 def get_threshold 方法中的屬性時,這些數字沒有相加。我已將輸入宣告為int但當我運行該方法時它似乎正在生成一個串列并且數字不相加。
有人能解釋一下我做錯了什么嗎?
這個想法是,該類將保存用戶的所有收入和養老金繳款詳細資訊,計算稅收狀況,并且程式將能夠列印相關的稅收資訊。
我已經在不使用類的情況下撰寫了代碼,但是想將它移到一個類中,以便我可以在需要時為其他客戶端請求資訊。
class Client:
def __init__(self, name, salary, bonus, intdiv, pensionpercent, pensionlump):
self.name = name
self.salary = salary
self.bonus = bonus
self.intdiv = intdiv
self.pensionpercent = pensionpercent / 100
self.pensionlump = pensionlump
@classmethod
def from_input(cls):
return cls(input('name'), int(input('salary')), int(input('bonus')), int(input('enter interest and divdends for the year')),
int(input('enter workplace pension contributions as a %')), int(input('enter total of any lump sum contributions'))
)
def get_threshold(self):
totalgross = (self.salary self.bonus self.intdiv, self.pensionlump)
print(totalgross)
c = Client.from_input()
c.get_threshold()
Code Returns:
name50000
salary5
bonus5
enter interest and divdends for the year5
enter workplace pension contributions as a %5
enter total of any lump sum contributions0
(15, 0)
Process finished with exit code 0
uj5u.com熱心網友回復:
您正在使用逗號在您的方法中創建一個元組
def get_threshold(self):
totalgross = (self.salary self.bonus self.intdiv, self.pensionlump) <-- comma is the cause
print(totalgross)
如果您需要單個值,您需要洗掉逗號,請改用 。或者無論您的公式要求什么。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/380127.html
上一篇:如何在codeigniter中使用MPDF添加水印影像
下一篇:是否可以使用多執行緒來加速腳本?
