Code
character_name = "Tom"
character_age = "50"
is_male = False
print("There once was a man named " + character_name + ", ").
print("he was " + character_age + " years old. ")
character_name = "Mike"
print("He really liked the name " + character_name + ",")
print("but didn't like being " + character_age + ".")
What I'm changing it to
character_name = "Tom"
character_age = 50
is_male = False
print("There once was a man named " + character_name + ", ").
print("he was " + character_age + " years old. ")
character_name = "Mike"
print("He really liked the name " + character_name + ",")
print("but didn't like being " + character_age + ".")
Error Code
/Users/praisekittens/PycharmProjects/Proj3/venv/bin/python /Users/praisekittens/PycharmProjects/Proj3/George.py
There once was a man named Tom,
Traceback (most recent call last):
File "/Users/praisekittens/PycharmProjects/Proj3/George.py", line 5, in <module>
print("he was " + character_age + " years old. ")
TypeError: can only concatenate str (not "int") to str
Process finished with exit code 1
Thoughts
I am brand new to coding and am following a four year old tutorial on Youtube from freeCodeCamp.org and everything had worked absolutely perfect until this part. It appears to me that the removal of the quotations marks is causing an issue with concatenating an int to a str.
When he takes the quotations away I do see that both character_age fields get highlighted yellow indicating an error. From how he is talking he makes me think he was able to run this code and have it work.
Questions
Can my code work without the quotations around the 50?
Why is he suggesting to do this in the first place? I was expecting some benefit from separating str and int and instead ran into this mildly frustrating error
What is the best code to use for this scenario?