【发布时间】:2017-10-09 21:09:26
【问题描述】:
我目前有这个任务:
word = input("Please enter a word: ")
print("The length of " + word + " is " + len(word = int(word)))
它运行,我输入Lilith Qua
我遇到一个错误说:
ValueError: invalid literal for int() with base 10: 'Lilith Qua'
有办法解决这个问题吗?
【问题讨论】:
-
您希望
len(word = int(word))做什么?, len(word)就足够了。 -
顺便说一句,最好使用string formatting 而不是串联。
print("The length of {} is {}".format(word, len(word)))它还负责转换。
标签: python