Click here to Skip to main content
15,881,812 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i was trying to write some numerical data in variables but i am getting a error.

What I have tried:

boy_name = "Steve"

print("I am " + boy_name + ",")

character_age = 11

print("I am " + character_age + ",")
Posted
Updated 1-Dec-18 19:37pm
Comments
Patrice T 2-Dec-18 1:13am    
and you plan to tell whatis the error message ?
Member 14068174 2-Dec-18 1:18am    
??
Patrice T 2-Dec-18 1:37am    
"but i am getting a error."
What error?
Member 14068174 2-Dec-18 1:51am    
This is the error

D:\Python\Projects\venv\Scripts\python.exe D:/Python/Projects/firstcode.py
I am Steve,
Traceback (most recent call last):
File "D:/Python/Projects/firstcode.py", line 7, in <module>
print("I am years old" + character_age)
TypeError: can only concatenate str (not "int") to str

Process finished with exit code 1
OriginalGriff 2-Dec-18 1:39am    
The error message: what the system said when it found it didn't like your code.
In this case:

print("I am " + character_age + ",")
TypeError: Can't convert 'int' object to str implicitly

1 solution

Because it won't automatically convert types.
Try:
print("I am " + str(character_age) + ",")
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900