Hi
I have attempted all the questions and exercises in this project and got the correct answer for all the questions but after submitting the code…it is saying wrong answer…why is that. I have matched my code with the perfect ones but still none of the answer is accepted by the system…please help quickly
Q-1: Count the Number of Lines
code is below:
def number_of_lines():
fhand = open(’/cxldata/datasets/project/mbox-short.txt’)
inp = fhand.read()
fhand.close()
count=len(inp.splitlines())
return count
number_of_lines()
got 1910 as answer but system not accepring
Q-2: Count the Number of Subject Lines
code is:
def count_number_of_lines():
count = 0
with open(’/cxldata/datasets/project/mbox-short.txt’) as f:
for line in f:
line = line.rstrip() # Remove new line characters from right
if line.startswith('Subject:'):
count = count + 1
return count
answer is 27. but not accepted by system
q-3: Find Average Spam Confidence
code:
def average_spam_confidence():
with open(’/cxldata/datasets/project/mbox-short.txt’) as f:
count = 0
spam_confidence_sum = 0
for line in f:
line = line.rstrip() # Remove new line characters from right
if line.startswith(‘X-DSPAM-Confidence:’):
var, value = line.split(’:’)
spam_confidence_sum = spam_confidence_sum + float(value)
count = count + 1
return spam_confidence_sum/count
average_spam_confidence()
answer: 0.7507185185185187
but still error on submission
and………same for other exercises as well