[英]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.