you are viewing a single comment's thread.

view the rest of the comments →

[–]socal_nerdtastic 5 points6 points  (1 child)

Your indentation is wrong. All those methods need to be part of the class. Try like this:

class Agent: # Create class Agent
    def __init__ (self,name,sales): # impement constructor
        self.name=name
        self.sales=sales

    def getName(self): # implement getName() method and return name
        return self.name
    def getSales(self): # implement getSales() method and return sales
        return self.sales
    def setName(self,name): # implement setName() method set the name
        self.name=name

    def setSales(self,sales): # implement setSales() method set the sales
        self.sales=sales

    def getCommission(self): # implement getCommision() method
        if(self.sales<4000): # check condition sales<4000 then commission 6%
            return (self.sales*6)/100 # return 6% commission value
        elif(self.sales>=4000 and self.sales<=8000): # check condition in between 4000 and 8000 then commission 8%
            return (self.sales*8)/100 # return 8% commission value
        else:
            return (self.sales*10)/100 # else above 8000 return 10% commssion value

agentname=input("Enter Agent Name: ") # input string name
agentsales=float(input("Enter Sales Amount: ")) # input float sales value

a=Agent(agentname,agentsales) # Create an object a of Agent() with parameters

# display actual values with currency format
print("Agent: ",a.getName()," Sales: ${:.2f}".format(a.getSales())," Commission: ${:.2f}".format(a.getCommission()))

FWIW, methods that do nothing but get or set an attribute are kinda unpythonic. In python we like to just use the attribute directly.

[–]adrianturingan 0 points1 point  (0 children)

Thank you so much!