+ 1

I don’t know where is the error. HELP! (Python)

I wrote this: birth_date = 2000 age = 2020 - int(birth_date) print ('is' + age ) And appeared this: Traceback (most recent call last): File "<string>", line 3, in <module> TypeError: Can't convert 'int' object to str implicitly I’m a beginner so maybe it’s easy but I don’t get it. Thank you for you time.

22nd Aug 2020, 5:57 AM
Neo
4 ответов
+ 3
Rei has given an excellent answer regarding the cause of the problem. A Pythonic way of creating the output would be print("Is",age) or print(f"Is {age}")
22nd Aug 2020, 8:16 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 4
in "is" + age you try to append an integer into string, that's the error. to fix it convert the integer to a string first "is" + str(age)
22nd Aug 2020, 6:00 AM
Rei
Rei - avatar
+ 1
You should type print(f”Is {age}”) or print(“is” + str(age)). ‘f’ stands for formatted string.
22nd Aug 2020, 11:26 AM
Mystic
Mystic - avatar
0
ooooohh thank you so much Rei. I feel like a pro. hahaha
22nd Aug 2020, 6:06 AM
Neo