Write a program where you can enter one translation pair at a time, (e.g. friend = kalyardi) and be told how many unique lines you have entered. You should not count duplicates. The program should stop asking for more words when you enter a blank line, and then print out how many unique translations you know.
For example:
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)!
Sometimes a word will have multiple (or similar) translations in which case, you want to count each translation separately, just by counting the number of unique lines.
我的程序是-
^{pr2}$当我运行我的程序的时候。在
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)!
我该怎么做才能修复我的程序被困了好长时间!!!!!!!在
1)将带有
input
的行移动到循环的最后一个语句。在2)在if块中,不要跳出循环,将新的翻译添加到
previous
列表中。在3)最后打印
len(previous)
。不需要count
变量。在另外一个很酷的方法,由AshwiniChaudhary在评论中建议。在
^{pr2}$编辑:如果必须匹配整个字符串
输出
试试这个
相关问题 更多 >
编程相关推荐