<jupyter_start><jupyter_text>"Geo Data Science with Python"  Notebook Exercise 4 optional Object TypesPlease insert your own answer cells below the task descriptions, if necessary.---  Part A: Python Objects (3 points)What does it mean if an object is mutable? What about immutable? Name at least two mutable and two immutable objects in Python.  --- Part B: Temperature Conversion (2 points)(note: wait with completing this task after we discussed functions in classes)For this task, let's the code the algorithm of the temperature conversion, which you have had forumulated in pseudocode during the course module 1.Write a Python function that converts the input Fahrenheit degree into its Celsius degree equivalent, based on the following equation: $C=5/9 * (F-32)$For that translate the equation into code, and enter it to replace the commented line (` YOUR CODE HERE`). Make sure to use the variable names `C` and `F` for the two temperature variables and keep the indent!<jupyter_code>""" Enter the conversion equation as a function below """

### YOUR CODE HERE<jupyter_output><empty_output><jupyter_text>In the next code cell, assign a variable `tempF` with any value for a Temperature in Degree-Fahrenheit. Then run the two cells further below to receive converted value to Degree-Celcius and test your code. You can try different values. If you are satisfied with the test, move on to the next task.<jupyter_code>"""Assign the variable 'tempF' with any value for a Temperature in Degree Fahrenheit."""

### YOUR CODE HERE

"""Check that your code returns the converted Temperature. """

### YOUR CODE HERE

# Check that your assigns a number to tempF and that it returns a correctly converted Temperature.

assert type(tempF) == float or int
assert tempConvert(32) == 0
assert tempConvert(50) == 10
assert tempConvert(100) == 37.77777777777778<jupyter_output><empty_output><jupyter_text>--- Part C:  Boolean Objects (2 Points)Assign the variable a, b and c with number or string values, so that all tests in the following cell return True.<jupyter_code>""" Assign the variable a, b and c with number or string values,
    so that all tests in the following cell return True """

### YOUR CODE HERE

"""Check that your code returns only True test results"""

Test1 = (type(c) == int)
Test2 = not b and bool(a)
Test3 = not(c) and a == 'spam'
Test4 = (type(c) == type(b))

print(Test1, Test2, Test3, Test4)
# Check that your code returns only True test results
assert Test1 == True
assert Test2 == True
assert Test3 == True
assert Test4 == True
assert type(a) == int or float or str
assert type(b) == int or float or str
assert type(c) == int or float or str<jupyter_output><empty_output><jupyter_text>--- Part D: Sequence operations with Strings and Lists (3 points)This tasks includes several string-list operations. You should process a string variable with the name `strIn` in the following way:Split the string variable `strIn` into a list of strings with a space delimiter. Use the method `split()`Then, using only list comprehensions, add % in front and at the end of every single word in the string list `strIn` (from previous task item). Assign the result to a new variable of the name `strListOut`.Add your code sequence in the following code block where it says YOUR CODE HERE. It will complete the following code block (function). You may code this in one or two steps. But, the variables for input (`strIn`) and output (`strListOut`) of your code sequence have to have the same names as stated in the task.Example: A string `"Spring is Awesome in Blacksburg"` would become a list like this: `['%Spring%','%is%', '%awesome%', '%in%', '%Blacksburg%']`<jupyter_code>def stringManipulation(strIn): # leave this line unchanged
    
    """Enter your answer below, do not change the indent!"""
    ### YOUR CODE HERE

    return(strListOut) # leave this line unchanged
"""Assing any string to the variable stringExample, 
    then use the function stringManipulation to check
    that your code correctly manipulated the input string."""

stringExample = "Add any sentence here!"

### YOUR CODE HERE

#Check that your code correctly manipulates the input string.

stringExample1 = "Spring is Awesome in Blacksburg"
assert stringManipulation(stringExample1) == ['%Spring%', '%is%', '%Awesome%', '%in%', '%Blacksburg%']
assert stringManipulation(stringExample1)[0][0] == '%'
assert stringManipulation(stringExample1)[0][-1] == '%'
assert type(stringManipulation(stringExample1)) == list<jupyter_output><empty_output><jupyter_text>--- Part E: List Comprehension with Number Lists Task E.1 (3 points)This tasks includes writing list comprehensions and other operations:* Write a a single list comprehension to print all the numbers in the range 1-100 that are either divisible by 10 or 11. Assign the result to a list `outList`. Use the built-in function `range()`.Enter the code for these task items in the cell below. Separate the blocks of the tasks items with a commented line,  starting with ` `. Use exactly these variable names, put your code below, where it states `YOUR CODE HERE` and keep the indent as provided.<jupyter_code>"""Write a list comprehension to find numbers divisible 
   by at least one of two given integer numbers. """

def divisionList(a,b): # leave this line unchanged
    
    """Enter your answer below, do not change the indent!"""
    ### YOUR CODE HERE

    return(outList) # leave this line unchanged

"""Adjust the two integer numbers to your liking."""
a = 15
b = 21

"""Check the result of your code."""
print("The following numbers between 1 and 100 are divisable by {} or {}: ".format(a,b))
print(divisionList(a,b))
print("\n")
#Check the result of your code.

assert divisionList(99,100) == [99, 100]
assert divisionList(15,21)  == [15, 21, 30, 42, 45, 60, 63, 75, 84, 90]<jupyter_output><empty_output><jupyter_text>Task E.2You have given two lists containing a student grade book. Below that, samples show you more sophisticated list comprehensions. Study those examples and experiment with them in the available cells, further below.<jupyter_code># Sample grade book data
#             0      1       2        3      4      5       6        7         8
headings = ["ID", "Name", "Gender", "HW1", "HW2", "HW3", "Exam1", "Exam2", "FinalExam"]

grades = [
#    0          1          2    3   4   5   6   7   8
 ["b0001", "<NAME>",    "F", 95, 87, 92, 88, 93, 90] # 0
,["b0002", "<NAME>",   "M", 55, 76, 89, 77, 82, 80] # 1
,["b0003", "<NAME>",  "F", 80, 75, 65, 70, 75, 80] # 2
,["b0004", "<NAME>", "M", 90, 90, 92, 95, 85, 94] # 3
,["b0005", "<NAME>", "F", 65, 52, 85, 45, 80, 82] # 4
]

# samples that use the Sample Grade Book in sample_grade_book.py
# Don't import this -- just use cut-and-paste to test the individual
#    expressions.

# display the gradebook (will need to type this one in 2 lines)
for g in grades:
    print(g)

# Larry Black's grade on Exam2
grades[3][7]

# Suppose you don't know the row/column numbers.
# finding Larry Black's row
headings.index('Name') # need to know the name column first

[g[headings.index('Name')] for g in grades] # names of all students

[g[headings.index('Name')] for g in grades].index('<NAME>') # find Larry Black's index

# to get Larry Black's complete row in the gradebook
grades[[g[headings.index('Name')] for g in grades].index('L<NAME>')]

# to get Larry Black's grades
grades[[g[headings.index('Name')] for g in grades].index('Larry Black')][headings.index('HW1'):]

#finding Exam2's column
headings.index('Exam2')

#finding Larry Black's grade on Exam2
grades[[g[headings.index('Name')] for g in grades].index('Larry Black')][headings.index('Exam2')]

# grades on Exam2
[g[7] for g in grades]
[g[headings.index('Exam2')] for g in grades]

# average on hw2
hw2 = [g[4] for g in grades]
float(sum(hw2))/len(grades)
# average on Exam2
float(sum([g[headings.index('Exam2')] for g in grades]))/len(grades)


# highest average
h = max([sum(g[3:])/float(len(g[3:])) for g in grades])
# index of that person
pindex = [sum(g[3:])/float(len(g[3:])) for g in grades].index(h)
# name and average
grades[pindex][1], h
# all together
grades[[sum(g[3:])/float(len(g[3:])) for g in grades].index(max([sum(g[3:])/float(len(g[3:])) for g in grades]))
][1], max([sum(g[3:])/float(len(g[3:])) for g in grades])<jupyter_output><empty_output><jupyter_text>Try the examples by copying & pasting them into the code cells below. Study their output. You may also add more code cells, if you like. This exercise will not be graded, but it is helpful to understand list comprehensions at a very deep level.<jupyter_code>### Try the examples in this code cell. (This will not be graded.)


### Try the examples in this code cell. (This will not be graded.)


### Try the examples in this code cell. (This will not be graded.)


### Try the examples in this code cell. (This will not be graded.)<jupyter_output><empty_output><jupyter_text>--- Part F: Dictionaries  Task F.1  (3 points)For this task, generate a new dictionary that merges the lists `headings` and `grades` from *Task E.2* into one dictionary of the name `students`. The dictionary `students` should be a nested dictionary: a dictionary of 5 dictionaries, with each of these 5 dictionaries containing a row of the list `grades`. Use the student ID's as key of the outer dictionary. Then use the remaining header lines as keys of the inner dictionaries and the remaing columns as values of the inner dictionaries. It is sufficient to include only one of the grade columns, e.g. `HW1` or `Exam2`.For the dictionary keys, use the name names as listed in `headings` above. Use appropriate object types for the content numbers and strings.<jupyter_code>"""Convert the list grades into a dictionary of the name students."""

### YOUR CODE HERE

#Check the result of your code.

assert type(students) == dict
assert list(students.keys())[0] == 'b0001'
assert len(students) == 5
assert len(students['b0001']) > 2
assert students['b0001']['Name'] == '<NAME>'
assert students['b0002']['Gender'] == 'M'<jupyter_output><empty_output><jupyter_text>Task F.2  (1 point)Now, given this dictionary, how can you look up a any student's (e.g. <NAME>) grade in any exam (e.g. Exam2) from the dictionary students? Write a chained list comprehension in the code cell below.<jupyter_code>"""Enter your code."""

### YOUR CODE HERE<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11074730354391371, 'fraction_numerical': 0.026675654853620955, 'mean_word_length': 4.583333333333333, 'pattern_counts': {'":': 0, '<': 46, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '70455', 'license': 'CC0-1.0', 'n_tokens_mistral': 3268, 'n_tokens_neox': 3007, 'n_words': 1414, 'path': 'Exercise04optional_ObjectTypes.ipynb', 'repo_name': 'GeoPythonVT/geosf21', 'size': '10421'}