<jupyter_start><jupyter_text>Homework 4This homework contains **two** problems<jupyter_code># importing modules used for displaying hints
import base64

# display functions
from IPython.display import Markdown, display<jupyter_output><empty_output><jupyter_text>Problem 1: A Dog's age in human yearsIf you own a dog, you've heard this rule: 1 year for Fido equals 7 years for you. While this may or may not be accuracte, it's a great idea for a programming problem :) If you're not familiar with this concept - [this]( https://pets.webmd.com/dogs/how-to-calculate-your-dogs-age) is a great article.  Your taskWrite a Python program to convert a dog's age to human years.To accomplish this, you need to create a function called `to_human_years(dog_years)` that accepts an integer `dog_years` and returns a `float` / decimal number which represents the age in human years. Rule to convert age from human years to dog years - * For the first two years - a dog year is equal to 10.5 human years* After that - Each dog year equals 4 human yearsExample Input:```     to_human_years(2)```Output:```    21   ```Fuction to create:```pythondef to_human_years(dog_years):         convert dog years to human years, and save your answer in the variable `human_years` below     human_years =         return human_years```**Hint:** You're given two rules for calculating a dog's age in human years. When you're given a set of rules, wherein you're required to conditionally run lines of code - `if`-`else` statements are the way to go! Test cases Once you've completed this program, please verify the correctness using the following input and output test cases:Once you've completed this program, please verify the correctness using the following input and output test cases:| Input(dog_years) | Output |         | :-: |:-------------: ||2| 21.0 ||5| 33.0 || 10 | 53.0|| 15 | 73.0|<jupyter_code>def to_human_years(dog_years): 
    
    if dog_years <= 2:
        human_years = dog_years * 10.5
    else:
        human_years = 21 + (dog_years - 2) * 4
    
    return human_years

to_human_years(15)<jupyter_output><empty_output><jupyter_text>Solution 1<jupyter_code># solution_1 = b'<KEY>'
# display(Markdown("```python\n{}\n```".format(base64.b64decode(solution_1).decode('utf-8'))))<jupyter_output><empty_output><jupyter_text>Problem 2: File Operations Now that you've written the function `to_human_years`, you can successfully convert a dog's age from "dog years" to "human years". This function lets you convert a dog's age to human years, but what if you had a database of dog-names and their current age - and you wanted to know their ages in human years?Here's a file which contains data pertaining to 11 dogs, namely - their name and age - `python-tutorials/data/dogs.csv` (feel free to open this file by double clicking on it via Finder, first)Once you open the file, it should look like this -```Bailey, 3Bella, 5Max, 18Lucy, 12Charlie, 5Molly, 2Buddy, 12Daisy, 10Rocky, 8Maggie, 6Chloe, 1```You can see that the file contains two columns separated by commas. A **`.csv`** file represents a comma-separated-values file. In this file - the first column represents the dog's **`name`** and the second column represents the **`age_in_dog_years`**. Your taskOpen this file in read mode in python - and run the **`to_human_years(dog_years)`** function for each dog entry, and print out the final result to console. This is what your output should look like - Output:```Bailey : 3 dog years, 25.0 human yearsBella : 5 dog years, 33.0 human yearsMax : 18 dog years, 85.0 human yearsLucy : 12 dog years, 61.0 human yearsCharlie : 5 dog years, 33.0 human yearsMolly : 2 dog years, 21.0 human yearsBuddy : 12 dog years, 61.0 human yearsDaisy : 10 dog years, 53.0 human yearsRocky : 8 dog years, 45.0 human yearsMaggie : 6 dog years, 37.0 human yearsChloe : 1 dog years, 10.5 human years```Fuction to create:```pythondef print_dog_ages_in_human_years(absolute_path_to_file):         Open the file from location = `absolute_path_to_file`     in read mode and read all the lines in the file     using the file.readlines() function     Iterate over each line (using a for loop)     Use the string split function to      separate the name and the age_dog_years          Convert the age_dog_years from string to integer     Convert age_dog_years to age_human_years using the function      `to_human_years` you wrote earlier     Print the output using string formatting, like this:         print("{} : {} dog years, {} human years".format(dog_name, age_dog_years, age_human_years))```<jupyter_code>def print_dog_ages_in_human_years(absolute_filename):
    with open(absolute_filename, 'r') as dog_data:
        for line in dog_data:
            current_line = line.rstrip('\n')
            current_line = current_line.split(',')
            name = current_line[0]
            dog_years = int(current_line[1])
            human_years = to_human_years(dog_years) 
            print("{name} : {dog_years} dog years, {human_years} human years".format(name=name, 
                                                                                     dog_years=dog_years, 
                                                                                     human_years=human_years))
            
        
        
    
    # Open the file from location = `absolute_path_to_file`
    # in read mode and read all the lines in the file
    # using the file.readlines() function

    # Iterate over each line (using a for loop)
    # Use the string split function to 
    # separate the name and the age_dog_years 
    
    # Convert the age_dog_years from string to integer

    # Convert age_dog_years to age_human_years using the function 
    # `to_human_years` you wrote earlier

    # Print the output using string formatting, like this: 
    #    print("{} : {} dog years, {} human years".format(dog_name, age_dog_years, age_human_years))

print_dog_ages_in_human_years('data/dogs.csv')
### NOTE: first find the absolute path to the dogs.csv file

# use the terminal to go to the directory where 
# these tutorials are saved and run the `pwd` command in this 
# 'python-tutorials/data' directory

# if you ran the jupyter notebook command in terminal from inside the 
# `python-tutorials` directory 
# then the `absolute_path_to_file` value below should work

absolute_path_to_file = 'data/dogs.csv'

## If it doesnt work, try the variable below
# absolute_path_to_file = '~/Desktop/Tutorials/python-tutorials/data/dogs.csv'
# Test your function

print_dog_ages_in_human_years(absolute_path_to_file)<jupyter_output><jupyter_text>Solution 2<jupyter_code>solution_2 = b'ZGVmIHByaW50X2RvZ19hZ2VzX2luX2h1bWFuX3llYXJzKGFic29sdXRlX3BhdGhfdG9fZmlsZSk6CiAgICAKICAgICMgT3BlbiB0aGUgZmlsZSBmcm9tIGxvY2F0aW9uID0gYGFic29sdXRlX3BhdGhfdG9fZmlsZWAKICAgICMgaW4gcmVhZCBtb2RlIGFuZCByZWFkIGFsbCB0aGUgbGluZXMgaW4gdGhlIGZpbGUKICAgICMgdXNpbmcgdGhlIGZpbGUucmVhZGxpbmVzKCkgZnVuY3Rpb24KCiAgICB3aXRoIG9wZW4oYWJzb2x1dGVfcGF0aF90b19maWxlLCAncicpIGFzIGZwOgogICAgICAgIGFsbF9saW5lcyA9IGZwLnJlYWRsaW5lcygpCgogICAgIyBJdGVyYXRlIG92ZXIgZWFjaCBsaW5lICh1c2luZyBhIGZvciBsb29wKQogICAgIyBVc2UgdGhlIHN0cmluZyBzcGxpdCBmdW5jdGlvbiB0byAKICAgICMgc2VwYXJhdGUgdGhlIG5hbWUgYW5kIHRoZSBhZ2VfZG9nX3llYXJzIAogICAgZm9yIGxpbmUgaW4gYWxsX2xpbmVzOgogICAgICAgIGRvZ19uYW1lLCBhZ2VfZG9nX3llYXJzID0gbGluZS5zcGxpdCgnLCcpCgogICAgIyBDb252ZXJ0IHRoZSBhZ2VfZG9nX3llYXJzIGZyb20gc3RyaW5nIHRvIGludGVnZXIKICAgICAgICBhZ2VfZG9nX3llYXJzID0gaW50KGFnZV9kb2dfeWVhcnMpCgogICAgIyBDb252ZXJ0IGFnZV9kb2dfeWVhcnMgdG8gYWdlX2h1bWFuX3llYXJzIHVzaW5nIHRoZSBmdW5jdGlvbiAKICAgICMgYHRvX2h1bWFuX3llYXJzYCB5b3Ugd3JvdGUgZWFybGllcgogICAgICAgIGFnZV9odW1hbl95ZWFycyA9IHRvX2h1bWFuX3llYXJzKGFnZV9kb2dfeWVhcnMpCgogICAgIyBQcmludCB0aGUgb3V0cHV0IHVzaW5nIHN0cmluZyBmb3JtYXR0aW5nLCBsaWtlIHRoaXM6IAogICAgIyAgICBwcmludCgie30gOiB7fSBkb2cgeWVhcnMsIHt9IGh1bWFuIHllYXJzIi5mb3JtYXQoZG9nX25hbWUsIGFnZV9kb2dfeWVhcnMsIGFnZV9odW1hbl95ZWFycykpCiAgICAgICAgcHJpbnQoInt9IDoge30gZG9nIHllYXJzLCB7fSBodW1hbiB5ZWFycyIuZm9ybWF0KGRvZ19uYW1lLCBhZ2VfZG9nX3llYXJzLCBhZ2VfaHVtYW5feWVhcnMpKQo='
display(Markdown("```python\n{}\n```".format(base64.b64decode(solution_2).decode('utf-8'))))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.07205882352941176, 'fraction_numerical': 0.03566176470588235, 'mean_word_length': 4.582079343365253, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 21, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '468801', 'license': 'CC-BY-3.0', 'n_tokens_mistral': 3217, 'n_tokens_neox': 2898, 'n_words': 769, 'path': 'Homework 4.ipynb', 'repo_name': 'shivam6294/python-tutorials', 'size': '8539'}