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