Help with a sytax error please

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Chucksta
    New Member
    • Feb 2010
    • 1

    Help with a sytax error please

    I'm getting a syntax error at the first if statement in my commission statement, indicated with carat. Thank you for your time in advance. It's probably something simple i'm still pretty new at this.
    Code:
    def sales():
        amount = int(input('Enter the monthly sales:'))
        return amount
    
    def advance_pay():
        advance = int(input('Enter the  amount of advance pay, or enter 0 if no advance pay was given'))
        return advance
    
    def commission():
        comm  =
        if amount() < 10000:
        [B]^[/B]this is where i'm getting the error.
            com = .10
        if 10000<= amount() <= 14999.99:
            com = .12
        if 15000 <= amount() <=17999.99:
            com = .14
        if 18000 <= amount() <= 21999.99:
            com = .16
        else:
            com = .18)
        return comm
    
    def pay_out():
        pay = amount*com - advance
        return pay
        
        
    def main():
        again = 'yes'
        while again == 'yes':
    
            amount()
            advance()
            comm()
            pay()
    
            print ('The pay is:$', pay)
            if pay < 0:
                 print ('The salesperson must reimburse the company.')
            again = input('Do you want to calculate another commission (yes/no):')
    main()
    Last edited by bvdet; Feb 23 '10, 12:52 PM. Reason: Add code tags
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    You cannot make a statement in the manner you are trying. Use an if/elif block instead of a series of if statements. Be aware of function scope with respect to variables. Use function arguments and return values to make assignments in other functions. Example:
    Code:
    >>> def a(arg):
    ... 	b = arg*10
    ... 	return b
    ... 
    >>> z = 8
    >>> zz = a(z)
    >>> zz
    80
    >>> def b(arg):
    ... 	return a(arg)*10
    ... 
    >>> print b(z)
    800
    >>>
    I reworked your function commission().
    Code:
    def commission():
        amount = sales()
        if amount < 10000:
            com = .10
        elif 10000<= amount <= 14999.99:
            com = .12
        elif 15000 <= amount <=17999.99:
            com = .14
        elif 18000 <= amount <= 21999.99:
            com = .16
        else:
            com = .18
        return com
    
    print commission()

    Comment

    Working...