<jupyter_start><jupyter_text>___ ___  Python Text Basics AssessmentWelcome to your assessment! Complete the tasks described in bold below by typing the relevant code in the cells.You can compare your answers to the Solutions notebook provided in this folder.  f-Strings 1. Print an f-string that displays `NLP stands for Natural Language Processing` using the variables provided.<jupyter_code>abbr = 'NLP'
full_text = 'Natural Language Processing'

print(f'{abbr} stands for {full_text}' )<jupyter_output>NLP stands for Natural Language Processing<jupyter_text>Files 2. Create a file in the current working directory called `contacts.txt` by running the cell below:<jupyter_code>%%writefile contacts.txt
First_Name Last_Name, Title, Extension, Email<jupyter_output>Overwriting contacts.txt<jupyter_text>3. Open the file and use .read() to save the contents of the file to a string called `fields`.  Make sure the file is closed at the end.<jupyter_code># Write your code here:

myfile = open('contacts.txt')
fields = myfile.read()
    
# Run fields to see the contents of contacts.txt:
fields
myfile.close()<jupyter_output><empty_output><jupyter_text>Working with PDF Files 4. Use PyPDF2 to open the file `Business_Proposal.pdf`. Extract the text of page 2.<jupyter_code>import PyPDF2

f = open('Business_Proposal.pdf', 'rb')
pdf_reader = PyPDF2.PdfFileReader(f)
page_two_text = pdf_reader.getPage(1).extractText()
print(page_two_text)<jupyter_output>AUTHORS:
 
<NAME>, Finance Chair, x345, <EMAIL>
 
<NAME>, Accounting Dir., x621, <EMAIL>
 
<NAME>, Sr. VP, x879, <EMAIL><jupyter_text>5. Open the file `contacts.txt` in append mode. Add the text of page 2 from above to `contacts.txt`. CHALLENGE: See if you can remove the word "AUTHORS:"<jupyter_code># Simple Solution:

with open('contacts.txt','a+') as c:
    c.write(page_two_text)
    c.seek(0)
    print(c.read())
# CHALLENGE Solution (re-run the %%writefile cell above to obtain an unmodified contacts.txt file):

with open('contacts.txt','a+') as c:
    c.write(page_two_text[8:])
    c.seek(0)
    print(c.read())<jupyter_output>First_Name Last_Name, Title, Extension, Email

 
<NAME>, Finance Chair, x345, <EMAIL>
 
<NAME>, Accounting Dir., x621, <EMAIL>
 
<NAME>, Sr. VP, x879, <EMAIL><jupyter_text>Regular Expressions 6. Using the `page_two_text` variable created above, extract any email addresses that were contained in the file `Business_Proposal.pdf`.<jupyter_code>import re

# Enter your regex pattern here. This may take several tries!
pattern = r"\"?([-a-zA-Z0-9.`?{}]+@\w+\.\w+)\"?"

re.findall(pattern, page_two_text)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11229946524064172, 'fraction_numerical': 0.013368983957219251, 'mean_word_length': 5.403422982885085, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 33, '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': '427572', 'license': 'Apache-2.0', 'n_tokens_mistral': 910, 'n_tokens_neox': 867, 'n_words': 284, 'path': '03-Python-Text-Basics-Assessment.ipynb', 'repo_name': 'ranjiGT/Python_Hackerrank', 'size': '2750'}