Skip to content Skip to sidebar Skip to footer

Error: Can't Assign To Function Call

I am trying to make a simple calculator for addition, and am experiencing a problem. print('welcome to calculator') # Print opening message print(' ') #Spacer int(sum1) = inp

Solution 1:

You are trying to assign to the result of an int() function call:

int(sum1) = input('number')

Everything on the left-hand side of the = sign should be a target to store the result produced by the right-hand side, and you are asking Python to store something in int(sum1).

If you wanted to convert the result of the input() call to an integer, you'll need to apply it to the return value of the input() call, not the variable in which you are storing that result:

sum1 = int(input('number'))

The same applies to both add1 cases in your code; use:

add1 = int(input('number'))

Now the right-hand side expression produces an integer result, to be stored in sum1 and add1 respectively.

Solution 2:

The statement int(sum1) = input('number') is invalid and should be sum1 = int(input('number')) in the second case you're casting the input into an int - which is what you want. In the first case you're trying to cast a function - what Python is complaining about.

Also this should be changed everywhere in your code !

Solution 3:

You have to convert it to integer, this is the correct way for that;

x = int(input("something"))

Post a Comment for "Error: Can't Assign To Function Call"