Ask coding questions

← Back to all posts
cant add number value in variable "character_age = 16"
Vishvajeet_sinh (5)

without 16 in quotation.
showing this error:

Traceback (most recent call last):
File "python", line 4, in <module>
TypeError: must be str, not int

Comments
hotnewtop
RyanRana (213)

The problem is you must convert everything in the print to a string by doing str(charecter_age), to learn more check out this cool python channel I found, and subscribe! https://www.youtube.com/channel/UCIta8OqsKjfE1knTU2DJlSQ

Vishvajeet_sinh (5)

@RyanRana got it. I am checking the channel rn.

Vishvajeet_sinh (5)

Not right now. I think the problem is, I haven't installed any packages. I don't know which one is necessary so I randomly installed Requests and Scripy.
I have windows 7 ultimate and having issue with updation so I have to use Cloud Coding. Help me.

MMarzouca (0)

@Vishvajeet_sinh I don't know what your code is but your problem is probably using a print function print("words" + character_age) you should try print("words" + str(character_age)) instead.

Vishvajeet_sinh (5)

@MMarzouca I'll try it. idk why my video tutorial guy is not doing STR stuff. thanks. :)

pyelias (2417)

Can you add a link to the full code?

Vishvajeet_sinh (5)

@pyelias this is full code:
character_age = "16"
print("his age was " + character_age + "at that time.")

(it's working fine with quotes, but I can't use 16 without double inverted commas. also, my question is, which package I should install as mandatory?

ash15khng (713)

@Vishvajeet_sinh You can't use 16 without the double inverted commas because the print() function takes in a string, and without the double inverted commas 16 is an int, so it doesn't work.
Also, you don't need any packages for this project.

MMarzouca (0)

@ash15khng You can take in an int just you can't add strings and ints inside the print function or anywhere for that matter. Just want to clarify so people don't go on thinking false information, but your explanation was suitable so if you did know and just didn't feel like explaining sorry.

ash15khng (713)

@MMarzouca Actually, I just forgot that mixing types didn't work, so thanks!