+ 2
PYTHON calculator
HELP ME HERE ALSO PLEASE. ************************************************************************************************** CODE: a = (input("enter value of a")) b = (input("enter value of b")) c = int(a) + int(b) print("The answer is: " + c) break ********************************************************************************************** OUTPUT: enter value of a10 enter value of b20 Traceback (most recent call last): File "C:/Users/user/PycharmProjects/test/calculator.py", line 20, in <module> print("The answer is: " + c) TypeError: can only concatenate str (not "int") to str
5 Respostas
+ 5
print("The answer is:", c)
+ 2
THANK YOU SO MUCH.
Is there another way for this to add
+ 2
Thank you
+ 1
print("The answer is: " + str(c))
0
It specifies the error TypeError: can only concatenate str(not "int") to str
Means you can only add a string (str) to another string (str) but can't add string to integer( int)
That means the error comes from the
print("The answer is: " +c) and is an integer
So to correct it use comma(,) instead
print("The answer is: ",c)
To get
The answer is: 30
OR
convert it to string using str() function
print("The answer is: " + str(c))