The Assessment -Python Project - Churn Emails - Count the number of lines

HI,

Below is my code and the assessment engine has not graded even though I get the line count as 1910 as suggested.

Please review and suggest if this can be graded.

def number_of_lines(filePath):
fhandle = open(filePath)
rdfile = fhandle.read()
fhandle.close()

count = 0

for line in rdfile:
    if '\n' in line:
        count = count + 1
return count

number_of_lines(’/cxldata/datasets/project/mbox-short.txt’)

Similarly for this one as well:

Python Project - Churn Emails - Count the Number of Subject Lines

def count_number_of_lines(filepath):
fhand = open(filepath)
count = 0

for line in fhand:
    line = line.rstrip()
    if line.startswith('Subject:'):
        count = count + 1
return count

count_number_of_lines(’/cxldata/datasets/project/mbox-short.txt’)

Please grade this one as well:
def average_spam_confidence(filepath):
fhand = open(filepath)
count = 0
sp_conf = 0.0

for line in fhand:
    if line.startswith('X-DSPAM-Confidence:'):
        words = line.split()
        sp_conf = sp_conf + float(words[1])
        count = count + 1
average_spam_confidence = sp_conf/count
return average_spam_confidence

average_spam_confidence(’/cxldata/datasets/project/mbox-short.txt’)

def find_email_sent_days(filepath):
fhand = open(filepath)
dayofweek = dict()
count= 0

for line in fhand:
    if line.startswith('From'):
        words = line.split()
        if (len(words) > 2):
            thrd_wrd = words[2]
            dayofweek[thrd_wrd] = dayofweek.get(thrd_wrd,0) + 1
return dayofweek

find_email_sent_days(’/cxldata/datasets/project/mbox-short.txt’)

def count_message_from_email(filepath):
fhand = open(filepath)
hist = dict()
for line in fhand:
if line.startswith('From '):
words = line.split()
emailaddress = words[1]
hist[emailaddress] = hist.get(emailaddress,0) + 1
return hist

count_message_from_email(’/cxldata/datasets/project/mbox-short.txt’)

Please grade the above one as well.

import re

def count_message_from_domain(filepath):
fhandle = open(filepath)
hist = dict()
for line in fhandle:
if line.startswith(‘From ‘) or line.startswith(‘From:’):
words = line.split()
emailaddress = words[1]
domains = emailaddress.split(’@’)
domainone = domains[1]
hist[domainone] = hist.get(domainone,0) + 1
return hist

count_message_from_domain(’/cxldata/datasets/project/mbox-short.txt’)

Output I have received:
{‘uct.ac.za’: 12,
‘media.berkeley.edu’: 8,
‘umich.edu’: 14,
‘iupui.edu’: 16,
caret.cam.ac.uk’: 2,
gmail.com’: 2}

Can you assess the above responses for the questions and suggest if I have completed the assignment related to Python Project - Churn Emails

def except_func(num):
try:
return num * num
except:
return ‘invalid number’

except_func(OH)
O/P:
NameError Traceback (most recent call last)
in
----> 1 except_func(OH)

NameError: name ‘OH’ is not defined

It should have been caught in except but it did not, so please clarify

Hi,

All assessments are graded by the assessment engine automatically. If you are facing a challenge please leave a comment there with a screenshot of your code with the error, and we will get back to you.

All the best.

HI Rajtilak,

As suggested, please see below for which I receive the error as follows even though the function gives correct output of -10

Function:
sum = 0
def special_func(num):
if num > 0 and type(num) == int:
i = 1
j = 0
fact = list()
while (i <= num):
if num == 1:
return 1
elif (num % i == 0):
fact.append(i)
if (i % 2 != 0):
sum = sum + i
i = i + 1
j = j + 1
print(i)
print(j)
else:
i = i + 1
return sum
elif (num < 0) or (type(num) != int):
return -10

special_func(6.5)
Output I received:
-10

Since the number is not an int and supplied number is a float we return -10 as the output as outlined in the question.

Assessment output message after submitting the code:
You should return -10 in case of non int type

I get the above message when I submit the code for all of the questions. So please clarify and ensure that the assessment is complete for all of the code submitted. Thanks for your help.

Hi,

Could you please share a screenshot of your code, and the error you are getting. That would be really very helpful.

Thanks.

image

image

image

image

image

image

image

image

image