Cmentosuu 2021-05-08 17:58 采纳率: 100%
浏览 40
已采纳

Python求指点,已经修改多次,系统还是提示部分正确,求大神指正。问题如图,代码已附上

 

 

ls=[]
words=input()
words=words.lower()
ls.append(words)
for c1 in ls:
    li=c1.split(" ")
str2=[]
i=0
for s in li:
    if s not in str2:
        str2.append(s)
        i+=1
h=int(i)
print("There are {} words in the paragraph.".format(h))
  • 写回答

4条回答 默认 最新

  • 冷寒越 2021-05-08 21:59
    关注

    不知道是不是要这个结果   先试试看

    import re
    
    def danci_count(strings):
        res = re.compile(r'\b[a-zA-Z]+\b', re.I).findall(strings)
        res_list = []
        for x in res:
            if x.lower() not in (y.lower() for y in res_list):
                res_list.append(x)
        return len(res_list)
    
    
    
    
    text = input("请输入一段话:")
    words = danci_count(text)
    print('There are {} words in the paragraph.'.format(words))
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据