我正在试着正确地计算辅音和辅音的数量。我还有其他需要做的部分。在
# Home work 4
from string import punctuation
fname = raw_input("Enter name of the file: ")
fvar = open(fname, "r")
punctuationList = "!#$%&'(),.:;?"
numLines = 0
numWords = 0
numChars = 0
numPunc = 0
numVowl = 0
numCons = 0
if line in "aeiou":
numVowl = + 1
else:
numCons += 1
for line in fvar:
wordsList = line.split()
numLines += 1
numWords += len(wordsList)
numChars += len(line)
for punctuation in punctuationList:
numPunc += 1
print "Lines %d" % numLines
print "Words %d" % numWords
print "The amount of charcters is %d" % numChars
print "The amount of punctuation is %d" % numPunc
print "The amount of vowls is %d" % numVowl
print "The amount of consonants is %d" % numCons
你可以试试这个:
你需要遍历行中的所有字符,测试它们是元音、辅音还是标点符号。在
我会写一个函数,当给定一个字符串时,它返回一个3元组的计数。在
然后在遍历文件时,将每一行传递给
^{pr2}$count_helper
。在相关问题 更多 >
编程相关推荐