Click here to Skip to main content
15,307,117 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
Member 14068174 2-Dec-18 1:51am
   
ya
OriginalGriff 2-Dec-18 1:57am
   
So when you want to ask for help, give us the information you have!

Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with.
The better the information you give us, then better our answer can be. In this case it's pretty trivial to work out what problem you are having, but that isn't always the case.
Help us to help you, and you get a better answer, quicker.
Member 14068174 2-Dec-18 1:59am
   
Thanks man ,this is my first day in python programming.can i connect with you on social media?
OriginalGriff 2-Dec-18 2:11am
   
You're welcome!
But no social media ... everything is done in public here, we aren't normally available for "private mentor" roles (and I get far too many emails every day as it is :laugh: )
Member 14068174 2-Dec-18 2:13am
   
Ok that,s fine but i wanna some advice from you privately.
OriginalGriff 2-Dec-18 2:17am
   
Why? What could we possibly converse about privately, that we can't publicly? It's not as if we have ever met! :laugh:
Member 14068174 2-Dec-18 4:11am
   
Man ,you are correct 100%.There are something that i need to talk with you privately :understand:

1 solution

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

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