-9
hp_character = input("Who's your favorite Harry Potter Character? ")
print(len(hp_character) + " is the number of characters.")

AIs say that it should be valid for versions 3.8 and newer, but VS Code says that it is a TypeError. It should say something like "10 is the number of characters."

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
  • 8
    Read the error message, it's pretty clear about the problem. – jonrsharpe Aug 10 '23 at 15:05
  • I don't know the connotation of that message but please don't be rude. I'm pretty new to coding and just needs help sometimes. Thank you. – ElleWoodsofCS Aug 10 '23 at 15:28
  • 1
    In friendlier language, when saying your code is producing an error, please include the full text of that error as formatted text as part of your question. – jmoerdyk Aug 10 '23 at 15:51
  • 1
    Since you're new, now is a good time to start practicing [how to debug your own code](https://ericlippert.com/2014/03/05/how-to-debug-small-programs/). Writing code is only one part of programming; knowing how to debug that code is essential because nobody writes perfect code in the first attempt. Reading and understanding error messages is an important part of debugging, because that's the interpreter telling you exactly what is wrong and where. Also, it's part of asking a good Stack Overflow question ([ask]) – Pranav Hosangadi Aug 10 '23 at 15:56
  • I apologize if I formatted my question & details the wrong way. Thank you! – ElleWoodsofCS Aug 10 '23 at 15:59
  • 2
    To everyone who replied, thank you so much for understanding my lack of knowledge. I will continue to improve my programming as well as my use of Stackoverflow. You guys inspire me. ☺️ – ElleWoodsofCS Aug 10 '23 at 16:07
  • 1
    Does this answer your question? [Print Combining Strings and Numbers](https://stackoverflow.com/questions/12018992/print-combining-strings-and-numbers) – Hovercraft Full Of Eels Aug 10 '23 at 17:26

1 Answers1

2

You have a type error, you need convert the len from int to string. See corrected code below:

hp_character = input("Who's your favorite Harry Potter Character? ")
print(str(len(hp_character)) + " is the number of characters.")
Suraj Shourie
  • 536
  • 2
  • 11