天天看點

How many words

Q:

You are learning a new language, and are having a competition to see how many unique words you know in it to test your vocabulary learning.

Write a program where you can enter one word at a time, and be told how many unique words you have entered. You should not count duplicates. The program should stop asking for more words when you enter a blank line.

For example:

Word: Chat
Word: Chien
Word: Chat
Word: Escargot
Word: 
You know 3 unique word(s)!
           

and

Word: Katze
Word: Hund
Word: Maus
Word: Papagei
Word: Schlange
Word: 
You know 5 unique word(s)!
           

and

Word: Salam
Word: 
You know 1 unique word(s)!
           

A:

word = input("Word: ")
list_word = []
num = 0
i = 0
while word:
  list_word.append(word)
  for n in range(len(list_word)):
    if len(list_word) == 1:
      pass
    else:
      if n != len(list_word) - 1:
        if list_word[len(list_word) - 1] == list_word[n]:
          num += 1
          list_word[n] = ""
  word = input("Word: ")
  i += 1
print("You know", len(list_word) - num, "unique word(s)!")