英文:
Why doesn't this code work, and how should I do it?
问题
hp_character = input("你最喜欢的哈利波特角色是谁?")
print(len(hp_character) + "是字符的数量。")
英文:
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."
答案1
得分: 2
你有一个类型错误,你需要将len从整数转换为字符串。请参考以下已更正的代码:
hp_character = input("你最喜欢的哈利·波特角色是谁?")
print(str(len(hp_character)) + " 是字符的数量。")
英文:
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.")
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论