Reputation:
I was making a VERY simple calculator, because I was bored, but for some reason it errors out with 'Can't assign to function call'. This is the code:
type=input("Please select a method.\n\n1.) Addition\n2.) Subtraction\n3.) Multiplication\n4.) Division\n\n")
if type == "1":
int(number1)=input("First number?")
int(number2)=input("Second number?")
answer=number1+number2
print ("The answer is " +answer +".")
if type == "2":
int(number1)=input("First number?")
int(number2)=input("Second number?")
answer=number1-number2
print ("The answer is " +answer +".")
if type == "3":
int(number1)=input("First number?")
int(number2)=input("Second number?")
answer=number1*number2
print ("The answer is " +answer +".")
if type == "4":
int(number1)=input("First number?")
int(number2)=input("Second number?")
answer=number1/number2
print ("The answer is " +answer +".")
else:
print("Pick a number from 1-4")
I feel like this is very obvious and I'm just being an idiot.
Upvotes: 0
Views: 95
Reputation: 2723
You need to convert the input string to int, not the variable it is getting assigned to:
if type == "1":
number1=int(input("First number?"))
number2=int(input("Second number?"))
answer=number1+number2
Upvotes: 2
Reputation: 1343
You are casting your variables to int
at the wrong time. You need to cast the input given to you as an integer, rather than cast the variable to an integer before a string value is given to you.
All instances similar to int(number1)=input("First number?")
need to be changed to number1 = int(input("First number?"))
.
This is called precedence.
Upvotes: 0