Home > Mobile >  I wanna make my output from a def function print out
I wanna make my output from a def function print out

Time:05-31

Here is my code and whenever I try to run the code it says "solution.printing() missing 1 required positional argument: 'self'". I just want my my def printing(self): to work. I am completely new to stack overflow so feel free to ask if my question is too vague to answer

class salary():
    def __init__(self, name, address, rate, hours):
        self.name = name
        self.address = address
        self.rate = rate
        self.hours = hours
    
        
class solution(salary):
    def max(self):
        maxhour = 40
        if self.hours > maxhour:
            self.exceed = self.hours - maxhour
            return self.exceed, self.hours

        else: 
            return self.hours
    def workhours(self):
        salad = self.hours * self.rate
        return salad
    
    def overtime(self):
        self.max()
        interestrate = self.rate * 0.1
        totalinterestrate = interestrate * self.exceed
        salad =totalinterestrate   (self.rate * 40)
        return salad

    def printing(self):
        self.workhours()
        self.overtime()
        print(solution.workhours(), solution.overtime())
        


name = input("Input your name: ")
address = input("Where do you live?: ")
rate = int(input("How much is your rate?: "))
hours = int(input("How many hours did you work?: "))

gle = salary(name, address, rate, hours)
solution.printing

CodePudding user response:

class salary():
    def __init__(self, name, address, rate, hours):
        self.name = name
        self.address = address
        self.rate = rate
        self.hours = hours
    
        
class solution(salary):
    

    
    def max(self):
        maxhour = 40
        if self.hours > maxhour:
            self.exceed = self.hours - maxhour
            return self.exceed, self.hours

        else:
            self.exceed = 0
            return self.hours
    def workhours(self):
        salad = self.hours * self.rate
        return salad
    
    def overtime(self):
        self.max()
        interestrate = self.rate * 0.1
        totalinterestrate = interestrate * self.exceed
        salad =totalinterestrate   (self.rate * 40)
        return salad

    def printing(self):
        self.workhours()
        self.overtime()
        print(self.workhours(), self.overtime())
        


name = input("Input your name: ")
address = input("Where do you live?: ")
rate = int(input("How much is your rate?: "))
hours = int(input("How many hours did you work?: "))

gle = solution(name, address, rate, hours)
gle.printing()

added self.exceed = 0 in max() when maxhour <= 40

changed last line of printing()

and finally, changed last two lines: you want to create the solution instance, not a salary instance.

CodePudding user response:

You don't specify what solution.exceed is at any point so i set it to make the code work, but this worked for me:

class salary():
    def __init__(self, name, address, rate, hours):
        self.name = name
        self.address = address
        self.rate = rate
        self.hours = hours
    
        
class solution(salary):
    def max(self):
        maxhour = 40
        if self.hours > maxhour:
            self.exceed = self.hours - maxhour
            return self.exceed, self.hours

        else: 
            return self.hours
    def workhours(self):
        salad = self.hours * self.rate
        return salad
    
    def overtime(self):
        self.exceed = 5 #added this since it wasn't defined
        self.max()
        interestrate = self.rate * 0.1
        totalinterestrate = interestrate * self.exceed
        salad =totalinterestrate   (self.rate * 40)
        return salad

    def printing(self):
        print(self.workhours(), self.overtime()) #just need this, you did it before with self.max()

#To actually run it and all
sol = solution('name','address',10,5)
sol.printing()
  • Related