[英]Im trying to print the amount of every verible from input, but my code doesn't write what I want it though it seems right. python
这是代码,尽管它应该给出不同的 output,但它一直给我同样的东西。
line = input('Car: ')
while line:
def word_count(str):
counts = dict()
words = str.split()
for word in words:
if word in counts:
counts[word] += 1
else:
counts[word] = 1
return counts
line = input('Car: ')
print( word_count(line))
这是我得到的 output:
{}
你可以试试
line = 'temp'
while line:
line = input('Car: ')
def word_count(str):
counts = dict()
words = str.split()
for word in words:
if word in counts:
counts[word] += 1
else:
counts[word] = 1
return counts
if line:
print(word_count(line))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.