Enrollments closing soon for Post Graduate Certificate Program in Applied Data Science & AI By IIT Roorkee | 3 Seats Left

  Apply Now

Python Project - Churn Emails

2 / 7

Python Project - Churn Emails - Count the Number of Lines

If we know the file is relatively small compared to the size of our main memory, we can read the whole file into one string using the read method on the file handle.

Example -

fhand = open('/cxldata/datasets/project/mbox-short.txt')
inp = fhand.read()
fhand.close()
INSTRUCTIONS
  • Define a function number_of_lines
  • Open the file mbox-short.txt which is located at /cxldata/datasets/project/mbox-short.txt
  • Read the file into one string by using read method on file handle
  • Write logic to count the number of lines
  • Return the count of the number of lines

PS - If your logic is correct then your function should return 1910. You can use "Hint" and "See Answer" if you are stuck.



Note - Having trouble with the assessment engine? Follow the steps listed here

Loading comments...