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)!")
  
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值