<jupyter_start><jupyter_text>1. Personal Details in a file<jupyter_code>name  = str(input('Enter your name: '))
email = str(input('Enter your mail: '))
phone = int(input('Enter your phone: '))
age   = int(input('Enter your age: '))


fd = open(name.split(' ')[0] + '.txt','w')

fd.write(name)
fd.write('\n')
fd.write(email)
fd.write('\n')
fd.write(str(phone))
fd.write('\n')
fd.write(str(age))

fd.close()<jupyter_output>Enter your name: <NAME>
Enter your mail: <EMAIL>
Enter your phone: 438593452
Enter your age: 23<jupyter_text>2. Phonebook (Adding User Details)<jupyter_code>def check_mail(mail):
    
    valid = False
    
    if len(mail.split('@')) == 2:                                   # If @ is present
        if(len(mail.split('@')[0]) != 0):                           # If username is there before @
            if (len(mail.split('@')[1].split('.')) == 2):           # If . is present      
                temp = mail.split('@')[1].split('.')             
                if(len(temp[0]) >= 1 and len(temp[1]) >= 1):        # If prefix and postfix is present for .
                    valid = True
                    
    return valid
def check_phone(phone):
    
    phone = str(phone)    
    c = 0
    for i in phone:
        if (ord(i) >= 48 and ord(i) <= 57):                        # Checking if character is a number
            c += 1   
    if (c == 10 and len(phone) == 10):                             # Checking if number of integres are 10
        return True
    else:
        return False
print('-'*20)
name  = str(input('Enter your name: '))
email = str(input('Enter your mail: '))
phone = str(input('Enter your phone: '))


if ((check_mail(email) == True) and (check_phone(phone) == True)):
    
    fd = open('Phonebook.txt','a')
    fd.write(name)
    fd.write(',')
    fd.write(email)
    fd.write(',')
    fd.write(phone)
    fd.write('\n')
    fd.close()
    print('-'*30)
    print('Data saved!')
    print('-'*30)
    
else:
    print('-'*30)
    print('Please enter valid details')
    print('Program Terminated')
    print('-'*30)<jupyter_output>--------------------
Enter your name: Prakash
Enter your mail: <EMAIL>
Enter your phone: 7586848586
------------------------------
Data saved!
------------------------------<jupyter_text>3. Reading Data from PhoneBook<jupyter_code>fd = open('Phonebook.txt','r')
text = fd.read()
fd.close()

users = text.split('\n')[:-1]

for user in users:
    name = user.split(',')[0]
    mail = user.split(',')[1]
    cell = user.split(',')[2]
    print(name,mail,cell)<jupyter_output>Ashish <EMAIL> 5673428573
Rajat <EMAIL> 8365834234
Harshit <EMAIL> 7849574854
Jagdish <EMAIL> 7584758495
Prakash <EMAIL> 7586848586<jupyter_text>4. Search Data based on Full-Name<jupyter_code>n = str(input('Enter the name: '))

for user in users:
    
    name = user.split(',')[0]
    mail = user.split(',')[1]
    cell = user.split(',')[2]
    
    if (name.lower() == n.lower()):
        print('-'*20)
        print('Name     :', name)
        print('Mail     :', mail)
        print('Phone    :', cell)
        print('-'*20)<jupyter_output>Enter the name: Ashish
--------------------
Name     : Ashish
Mail     : <EMAIL>
Phone    : 5673428573
--------------------<jupyter_text>5. Search Data based on Mail-ID<jupyter_code>m = str(input('Enter the mail: '))

for user in users:
    
    name = user.split(',')[0]
    mail = user.split(',')[1]
    cell = user.split(',')[2]
    
    if (mail.lower() == m.lower()):
        print('-'*20)
        print('Name     :', name)
        print('Mail     :', mail)
        print('Phone    :', cell)
        print('-'*20)<jupyter_output>Enter the mail: <EMAIL>
--------------------
Name     : Ashish
Mail     : <EMAIL>
Phone    : 5673428573
--------------------<jupyter_text>6. Search data with insufficient Information (Name)<jupyter_code>n = str(input('Enter the name: '))


for user in users:
    
    name = user.split(',')[0]
    mail = user.split(',')[1]
    cell = user.split(',')[2]
    
    if (n.lower() in name.lower()):
        print('-'*20)
        print('Name     :', name)
        print('Mail     :', mail)
        print('Phone    :', cell)
        print('-'*20)<jupyter_output>Enter the mail: Ash
--------------------
Name     : Ashish
Mail     : <EMAIL>
Phone    : 5673428573
--------------------
--------------------
Name     : Prakash
Mail     : <EMAIL>
Phone    : 7586848586
--------------------<jupyter_text>7. Search data with insufficient Information (Phone)<jupyter_code>c = str(input('Enter the phone: '))

for user in users:
    
    name = user.split(',')[0]
    mail = user.split(',')[1]
    cell = user.split(',')[2]
    
    if (c in cell):
        print('-'*20)
        print('Name     :', name)
        print('Mail     :', mail)
        print('Phone    :', cell)
        print('-'*20)<jupyter_output>Enter the phone: 95
--------------------
Name     : Harshit
Mail     : <EMAIL>
Phone    : 7849574854
--------------------
--------------------
Name     : Jagdish
Mail     : <EMAIL>
Phone    : 7584758495
--------------------<jupyter_text>8. Adding New User (Function)<jupyter_code>def add_user():
    
    print('-'*20)
    name  = str(input('Enter your name: '))
    email = str(input('Enter your mail: '))
    phone = str(input('Enter your phone: '))


    if ((check_mail(email) == True) and (check_phone(phone) == True)):

        fd = open('Phonebook.txt','a')
        fd.write(name)
        fd.write(',')
        fd.write(email)
        fd.write(',')
        fd.write(phone)
        fd.write('\n')
        fd.close()
        print('-'*30)
        print('Data saved!')
        print('-'*30)

    else:
        print('-'*30)
        print('Please enter valid details')
        print('Program Terminated')
        print('-'*30)
add_user()<jupyter_output>--------------------
Enter your name: Ria
Enter your mail: <EMAIL>
Enter your phone: 7546352435
------------------------------
Data saved!
------------------------------<jupyter_text>9. Searching User based on Name<jupyter_code>def search_name(n):

    
    fd = open('Phonebook.txt','r')
    text = fd.read()
    fd.close()
    users = text.split('\n')[:-1]


    for user in users:

        name = user.split(',')[0]
        mail = user.split(',')[1]
        cell = user.split(',')[2]

        if (n.lower() in name.lower()):
            print('-'*20)
            print('Name     :', name)
            print('Mail     :', mail)
            print('Phone    :', cell)
            print('-'*20)
search_name('Ria')<jupyter_output>--------------------
Name     : Ria
Mail     : <EMAIL>
Phone    : 7546352435
--------------------
{'fraction_non_alphanumeric': 0.2270597127739985, 'fraction_numerical': 0.037037037037037035, 'mean_word_length': 1.8890829694323144, 'pattern_counts': {'":': 0, '<': 46, '<?xml version=': 0, '>': 48, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '299930', 'license': 'Apache-2.0', 'n_tokens_mistral': 2380, 'n_tokens_neox': 2218, 'n_words': 501, 'path': 'Week - 5/Phone Book/Phone Book.ipynb', 'repo_name': 'AshishJangra27/Data-Science-Specialization', 'size': '6766'}