Python newbie and unsupported operand
Question: I'm just learning python and am trying to make a program that calculates loan
rates. I keep getting an unsupported operand type for *: 'function' and 'int.'
with references to lines 14 and 8. I'm not sure what I'm doing wrong. Here is
the code:

    
    
    from sys import argv
    
    def payment(amt, rate, yrs) :
        def p(yrs) :
            return 12 * yrs
        def r(rate) :
            return rate / 100 / 12
        return (r * amt) / (1 - ((1 + r) ** (-p)))
    
    if __name__ == "__main__" :
        amt = int(argv[1])
        rate = float(argv[2])
        yrs = int(argv[3])
        print("$%.2f" % payment(amt, rate, yrs))
    


Answer: As mentioned in the comments, your immediate problem is that (as your
exception says) you tried to multiply an integer with a function, and that
doesn't make sense. A naïve fix for that would be to call the functions you've
defined, as per Mehmet's answer:

    
    
    return (r(rate) * amt) / (1 - ((1 + r(rate)) ** (-p(yrs))))
    

However, you don't really need those functions at all. A simpler version of
your `payment()` function might look like this:

    
    
    def payment(amt, rate, yrs) :
        p = 12 * yrs
        r = rate / 100 / 12
        return (r * amt) / (1 - ((1 + r) ** (-p)))
    

Notice that instead of defining functions inside `payment()`, here we're
simply assigning the result of the calculation to a variable in each case.

