多少字?需要帮助。

时间:2015-12-17 03:47:27

标签: list words

我有这个代码,它几乎是正确的:

list = []
list = input('Word: ')
while list != '':
  list = input('Word: ')
for Word in list:
  print(list)

但它需要 - 你知道3个独特的单词! - 之后。

有人可以帮我完成这段代码吗,因为我已经尝试了一切来解决这个问题,这让我发疯了

2 个答案:

答案 0 :(得分:0)

count=0 
//increments when a unique word is entered.
var1=""
i=0
list=[]
var1=input('Word: ')
while(var1!="" && var1!=" "):
 //stops when the input is space or null
               if var1 not in list 
//checks if the word is already present
                   list[i]=var1
                   i=i+1
                   count=count+1
                   var1=input('Word: ')
print("Printing your unique words")
i=0
while(i<count) // prints unique words
        print(list[i] "\n")
        i=i+1

Print("No. of unique words entered"+count)
//prints no. of unique words

这将完全符合您的要求。如果发生某些错误,请在评论中告诉我。当用户输入空格或什么都没有时,程序将停止输入。

答案 1 :(得分:0)

这是给使用Python 3的那些人的,这是我完成希腊语学习-编程入门(Python)课程时所做的。

words = []
word = input('Word: ')
while word != '':
    if word not in words:
        words.append(word)
        word = input('Word: ')
print('You know', len(words), 'unique word(s)!')

希望它可以在将来帮助任何人。

相关问题