我试图搜索文本文件并确定文本文件中有多少行、元音、辅音和数值/字符。我的元音、辅音和数字输出值似乎没有正确计算。线路输出总计已正确计算。
ein = input("Please enter file name: ")
vowels = set("AEIOUaeoiu")
cons = set("BCDFGHJKLMNPQRSTVWXYZbcdfghjklmnpqrstvwvyz")
num = set("1234567890")
count = 0
Vcount = 0
Ccount = 0
Ncount = 0
with open(ein) as ein_handle:
for line in ein_handle:
count += 1
for line in ein_handle:
if line in vowels:
Vcount += 1
elif line in cons:
Ccount += 1
elif line in num:
Ncount += 1
print("the file has",count,"lines.")
print("the file has",Vcount,"vowels.")
print("the file has",Ccount,"consonants.")
print("the file has",Ncount,"numerical characters.")
一只萌萌小番薯
慕码人8056858
相关分类