+ 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 ответов
+ 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