+ 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.
4 RĂ©ponses
+ 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}")
+ 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)
+ 1
You should type print(fâIs {age}â) or print(âisâ + str(age)). âfâ stands for formatted string.
0
ooooohh thank you so much Rei. I feel like a pro. hahaha