0

I am trying to put an exponent in my code and for some reason it keeps giving me a "can't assign operator" error for it and I'm not sure why.

I changed to code to not have any 'int' and I tried importing math because I wasn't sure if exponents needed to be imported, clearly neither worked. Other than these, I'm not sure what is wrong with the code.

name = input("Enter name: ")

bank_name = input("Enter bank name: ")

initial_investment = input("Enter initial investment amount: ")

annual_interest_rate = input("Enter annual interest rate: ")

investment_years = input("Enter number of years to invest money: ")

investment_months = investment_years * 12

monthly_interest_rate = ((int(annual_interest_rate) / 12) / 100)

MIR^IM = (1 + int(monthly_interest_rate)) ** (int(investment_months))

final = int(initial_investment) * int(MIR^IM)

gain = int(final) - int(initial_investment)

I wanted to MIR^IM variable to produce (1 + monthly interest rate) ^ investment months

7
  • Format your code with {} button Commented Apr 12, 2019 at 5:37
  • 5
    This is because of ^. You are trying to assign to expression MIR ^ IM. Change name of the variable to MIR_IM. Note: ^ doesn't stand for power. Commented Apr 12, 2019 at 5:38
  • Can you share the Traceback? Commented Apr 12, 2019 at 5:38
  • @bubble thanks I appreciate it that worked and yeah i learned that about 20 minutes ago. Just started like a week ago at most. Commented Apr 12, 2019 at 5:42
  • @Carter I have no idea what that is or how to get it, but if you'd let me know I'd appreciate it. Also, someone already answered my question, but I'd still like to know what a traceback is and how to share it. Commented Apr 12, 2019 at 5:43

2 Answers 2

1

You can't have an operator as a variable name. In your case ^ (XOR) is the operator causing the issue.

XOR Sets each bit to 1 if only one of two bits is 1

Just change your variable name from MIR^IM to something like:

MIR_IM = (1 + int(monthly_interest_rate)) ** (int(investment_months))
Sign up to request clarification or add additional context in comments.

Comments

0

"MIR^IM" is not a valid name for a Python identifier.

From the python documentation, for a name of an identifier, you can use characters of the English alphabet(a-z, A-Z), digits(0-9; not allowed as first character), underscore(_), and some restricted range of unicode characters (but this is very discouraged in practice!). '^' is not allowed in a name of an identifier.

So you have to change the name of your variable to fit the rule.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.