I dont see anything wrong with this code

1

This is weird. How does this code not work? Does the computer confuse between “age” and age in the last line? It can’t be, right? Basically, it should just print out a string and the value of the variable. Any idea what’s wrong with this code?
Thanks,

You can print age just fine but you can’t add it to a string. You can only add strings to strings. Maybe you could turn it into a string with str()?

i am so confused. I am watching a tutorial. This guy says i dont need “” mark if i store an int value. We just named it differently. but how come his variable works?

I’m not familiar with the video, but that code should produce an error. In fact it’s highlighted like that because the text editor knows it’s invalid. It’s possible that this will produce an error later in the video and he’ll fix it or he may be in the middle of editing.

In the video, the code with the character_age = 50 is never executed. The teacher is just explaining if you want to use a number (integer), you do not use quotation marks around the number.

Jeez… that would confuse a lot of beginners like me. I just found out that to print str and int, I have to use comma, not the plus sign. Thanks all

Also, as @greentart suggested, you can just use the str function to convert the integer to a string to concatenate the other string with the integer.

age = 30
print("The age is " + str(age))

You can also use something called an f-string to accomplish the same thing.

age = 30
print(f'The age is {age}')