<jupyter_start><jupyter_text>write a program to count messages sent from <EMAIL><jupyter_code>count = 0 
handle = open('mbox.txt')
for line in handle:
    if line.strip().startswith('From: '):
        if '<EMAIL>' in line:
            count += 1 
handle.close()
count<jupyter_output><empty_output><jupyter_text>write a program to count messages sent to <EMAIL><jupyter_code>count = 0 
handle = open('mbox.txt')
for line in handle:
    if line.strip().startswith('To: '):
        if '<EMAIL>' in line:
            count += 1 
handle.close()
count<jupyter_output><empty_output><jupyter_text>write a program to count messages sent from uct.ac.za domain<jupyter_code>count = 0 
handle = open('mbox.txt')
for line in handle:
    if line.strip().startswith('From: '):
        if '@uct.ac.za' in line:
            count += 1 
handle.close()
count<jupyter_output><empty_output><jupyter_text>write a program to get the subjects of messages sent from <EMAIL><jupyter_code>lines = open('mbox.txt').read().split('\n')
for i in range(len(lines)):
    if lines[i].startswith('From: '):
        if '<EMAIL>' in lines[i]:
            print(lines[i+1])<jupyter_output>Subject: [sakai] svn commit: r39772 - content/branches/sakai_2-5-x/content-impl/impl/src/java/org/sakaiproject/content/impl
Subject: [sakai] svn commit: r39750 - event/branches/SAK-6216/event-util/util/src/java/org/sakaiproject/util
Subject: [sakai] svn commit: r39620 - citations/branches/sakai_2-5-x/citations-tool/tool/src/webapp/vm/citation
Subject: [sakai] svn commit: r39619 - search/branches/sakai_2-5-x/search-impl/impl/src/java/org/sakaiproject/search/journal/impl
Subject: [sakai] svn commit: r39592 - util/branches/sakai_2-5-x/util-util/util/src/java/org/sakaiproject/util
Subject: [sakai] svn commit: r39527 - in event/trunk/event-api/api/src/java/org/sakaiproject/event: api cover
Subject: [sakai] svn commit: r39524 - portal/branches/sakai_2-5-x/portal-impl/impl/src/java/org/sakaiproject/portal/charon/handlers
Subject: [sakai] svn commit: r39523 - portal/trunk/portal-impl/impl/src/java/org/sakaiproject/portal/charon/handlers
Subject: [sakai] svn commit: r39496 - user/branches/sakai[...]<jupyter_text>write a program to get the username of all messages sent from @uct.ac.za domain<jupyter_code>result = ''
for i in range(len(lines)):
    if lines[i].startswith('From: '):
        if '@uct.ac.za' in lines[i]:
            target_line = lines[i]
            target_line = target_line.replace('From: ', '')
            username = target_line.split('@')[0]
            if username not in result:
                result += username + '\n'
print(result)<jupyter_output>stephen.marquard
david.horwitz<jupyter_text>write a program to let the user to enter the file name, then print the number of lines in that file<jupyter_code>def read_file():
    file_name = input('enter file name: ')
    handle = open(file_name)
    lines = handle.read().split('\n')
    print('there is {} lines in the file {}'.format(len(lines), file_name))
read_file()
read_file()
read_file()
read_file()
def read_file_exception():
    try:
        file_name = input('enter file name: ')
        handle = open(file_name)
        lines = handle.read().split('\n')
        print('there is {} lines in the file {}'.format(len(lines), file_name))
    except FileNotFoundError:
        print('file not found')
read_file_exception()
read_file_exception()
read_file_exception()<jupyter_output>enter file name:  test1.txt
{'fraction_non_alphanumeric': 0.13979118329466358, 'fraction_numerical': 0.019721577726218097, 'mean_word_length': 3.920114122681883, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '394927', 'license': 'MIT', 'n_tokens_mistral': 1262, 'n_tokens_neox': 1220, 'n_words': 266, 'path': 'notebooks/ch7_files_problems.ipynb', 'repo_name': 'motazsaad/410700', 'size': '3562'}