I'm new to classes in any programming language, however currently I am trying to create a program that will calculate a users tax position based on inputs.
The issue I'm having is that when I call the attributes in method def get_threshold the figures are not adding up. I have declared the input as int but it appears to be generating a list when I run the method and the numbers don't add up.
Is anybody able to kindly explain what I have done wrong?
The idea will be that the class will hold all of the user's income and pension contribution details, calculate the tax position and the program will be able to print relevant tax information.
I have written the code without using classes however would like to move it into a class so that I can request information for additional clients if it's required.
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
CodePudding user response:
You are creating a tuple in your method with the comma
def get_threshold(self):
totalgross = (self.salary self.bonus self.intdiv, self.pensionlump) <-- comma is the cause
print(totalgross)
If you want a single value you need to remove the comma, use a instead. Or whatever your formula calls for.