为什么这段代码不起作用,应该如何做?

huangapple go评论108阅读模式
英文:

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.")

huangapple
  • 本文由 发表于 2023年8月10日 23:03:04
  • 转载请务必保留本文链接:https://go.coder-hub.com/76877003.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定