编写一个程序,您可以一次输入一个翻译对(例如friend = kalyardi)并被告知您输入了多少个独特的行。你不应该计算重复。当你输入一个空行时,程序应该停止询问更多的单词,然后打印出你知道多少个独特的翻译。
例如:
Word: friend = kalyardi Word: happy = jipa-jipa Word: bird = jirripirdi Word: friend = kalyardi Word: You know 3 unique word translation(s)!
和
Words: bandicoot = jarlku
Word: bandicoot = jarlku
Word: dog = jarntu
Word: dog = kuna-palya
Word: kangaroo = kanyarla
Word: cockatoo = ngaarnkamarda
Word:
You know 5 unique word translation(s)!
有时一个单词会有多个(或类似的)翻译,在这种情况下,您希望单独计算每个翻译,只需计算唯一行的数量即可。
我的程序读取 -
translation = input("Word: ")
count = 0
previous = []
while translation != "":
if translation not in previous:
count = (count - 1)
translation = input("Word: ")
else:
break
print("You know", count, "unique translation(s)!")
当我运行我的程序时,它确实如此。
Word: bandicoot = jarlku
Word: bandicoot = jarlku
Word: dog = jarntu
Word: dog = kuna-palya
Word: kangaroo = kanyarla
Word: cockatoo = ngaarnkamarda
Word:
You know -6 unique translation(s)!
我应该怎么做才能解决我的程序被卡住了好久!!!!!!!