I am a beginner in Python and am working on an assignment. I keep getting TypeError: unsupported operand type(s) for -: 'int' and 'function' even after researching the error and applying the suggested fixes. I’m not looking for anyone to hand me a solution, but I would appreciate a second look. I’m missing something but I don’t know what. This is the section of code I’m having trouble with:
month = 0
interestYDT = 0
balance = int(raw_input ("Enter balance on credit card: "))
annualInterestRate = float(raw_input ("Enter annual interest rate as a decimal: "))
monthlyPaymentRate = float(raw_input ("Enter minimum monthly payment rate as a decimal: "))
previousbalance = balance
#
def monthlyInterestRate(annualInterestRate):
return float(annualInterestRate/12)
#
if month <= 12:
def minimumMonthlyPayment(previousbalance):
return (previousbalance * monthlyPaymentRate)
def monthlyInterest(monthlyInterestRate):
return (1 + monthlyInterestRate)
minMonPay = minimumMonthlyPayment
monInt = monthlyInterest
newbalance = ((previousbalance - minMonPay) * (monInt))
interestYDT = (interestYTD + montInt)
previousbalance = (newbalance)
print ''
print ('Month:' (month))
print ('Minimum monthly payment: $ ' (round(minimumMonthlyPayment, 2)))
print ('Remainging balance: $ ' (round(newbalance, 2)))
print ' '
month = (month + 1)
This is the entire error I get:
Traceback (most recent call last):
File "C:/Users/Karla/Documents/_MIT 600X Introduction to CS and Prog/Assignments/Week2/kmarciszewski_week2_Problemset_Problem1.py", line 33, in <module>
newbalance = ((previousbalance - minMonPay) * (monInt))
TypeError: unsupported operand type(s) for -: 'int' and 'function'
I’d really appreciate any insight. Thank you.
In order to call a function you must add parens after the function name, as well as any required parameters.
In these two lines
you assign the functions to the names minMonPay, monInt, but you don’t actually call them. Rather, you would need to write something like:
This definition
gives you a function that takes one parameter and calls it previousBalance. It has nothing to do with the variable you created earlier in your code. In fact, I suggest you rename it, it can only serve to confuse you as a beginner.
Further, the functions you’ve created are so simple, and only used once each, that it might be in your interest to remove them and inline the code.
Dont forget to update the line that incorrectly uses the minimumMonthlyPayment function if you do this.