FAQ: Errors in Python - Type Errors

This community-built FAQ covers the “Type Errors” exercise from the lesson “Errors in Python”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Analyze Financial Data with Python
Build Chatbots with Python
Build Python Web Apps with Flask

Learn Python 3

FAQs on the exercise Type Errors

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!
You can also find further discussion and get answers to your questions over in Language Help.

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head to Language Help and Tips and Resources. If you are wanting feedback or inspiration for a project, check out Projects.

Looking for motivation to keep learning? Join our wider discussions in Community

Learn more about how to use this guide.

Found a bug? Report it online, or post in Bug Reporting

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

hello! <3

why would this correction not be considered a viable solution?
thnx.

print(“The rectangle area is” + str(area) )

8 Likes

Has anyone figured this out?

Would also like to know why this isn’t accepted as a solution.

I think it would have more to do with style, as you are debugging some one else’s code that using their style to remain consistent is key. You’ll notice that it does print correctly.

Please let me know if I’m wrong though!

1 Like

It is a viable solution except Codecademy is very specific and narrow in the answer they want. A lot of these problems may have multiple solutions but they will mark them wrong if it’s not the exact one they’re looking for.

I did the same thing as you, the output terminal doesn’t say I have a TypeError but CodeAcademy won’t let me progress. Extremely frustrated right now.

I just reset my code, tried it again and for some reason it worked. I have no idea.

Hi, I just used the same style the coder used to print the area of the triangle and circle. So just change the ‘+’ to a ‘,’ and all went well.

2 Likes

Just put a comma. It looks like this:

print(“The triangle area is”, area)

Agreed - I wish they would build their tests to accept any valid solution, not just the exact one they’re looking for!

My main question is what sets " , " apart from " + "? Why do I need to make area a string when I use " + " but not a comma?

When you pass arguments of any type to print it effectively calls them with the str() function before outputting them as text. What you’re doing with the comma , is passing multiple arguments to the print function. Since each function is converted to text of some form before printing this is fine.
https://docs.python.org/3/library/functions.html#print

The + for the string type is concatenation that joins two strings into a new string. In that case the concatenation is performed first and then you’re passing a singular string object to print which is fine too.

Worth knowing both options exist and the differences between them.

3 Likes

i was writhing a whole big answer but mistakenly i just escaped and whole text got removed, sorry :frowning:

This worked for me:

print("The rectangle area is " + str(area))