我对Python和一般的编码是完全陌生的。我需要写一个代码,允许用户输入许多行,当他们完成写他们的多个句子,他们输入一个句点停止程序,然后程序会告诉用户有多少字被输入。我该怎么做呢?你知道吗
到目前为止,我掌握的情况如下:
print("Enter as many lines of text as you want.")
print("When you're done, enter a single period on a line by itself.")
while True:
print("> ", end="")
line = input()
if line == ".":
break
totalWords = line.split()
newWords = totalWords.append(line)
wordCount = len(newWords)
print("The number of words entered:" , wordCount, "")
您应该将
content
设置为外循环。你知道吗此外,大多数更改序列/映射项的函数都返回
None
。所以newWords = totalWords.append(line)
总是返回None
。你知道吗相关问题 更多 >
编程相关推荐