+ 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

19th May 2019, 12:21 PM
Adarsh Mamgain
Adarsh Mamgain - avatar
5 Respostas
+ 5
print("The answer is:", c)
19th May 2019, 12:25 PM
Paul
Paul - avatar
+ 2
THANK YOU SO MUCH. Is there another way for this to add
19th May 2019, 12:31 PM
Adarsh Mamgain
Adarsh Mamgain - avatar
+ 2
Thank you
19th May 2019, 1:26 PM
Adarsh Mamgain
Adarsh Mamgain - avatar
+ 1
print("The answer is: " + str(c))
19th May 2019, 1:04 PM
Diego
Diego - avatar
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))
25th Apr 2021, 4:58 PM
Nafisa Mohamud
Nafisa Mohamud - avatar