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))

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

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))

 

优化后还是错误

import string
text = input("")
for p in string.punctuation:
    text=text.replace(p,"").lower()
text=text.split(' ')
words = len(set(text))
print('There are {} words in the paragraph.'.format(words))