Ask coding questions

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

without 16 in quotation.
showing this error:

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

Voters
ManuelOliverKin
Feras123
RyanRana
Vishvajeet_sinh
Comments
hotnewtop
RyanRana

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

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

Vishvajeet_sinh

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

@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

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

pyelias

Can you add a link to the full code?

Vishvajeet_sinh

@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

@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

@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

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