擅长:python、mysql、java
<p>因为您正在从文件中读取行,所以每行都以'\n'结尾</p>
<p>试着这样做。你知道吗</p>
<pre><code>def checkvalidword(tempword):
tally = 0
file = open("words.txt")
for x in file:
if x.strip() == tempword:
tally+=1
print("Added to the tally")
</code></pre>
<p>注意x.strip()</p>