<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 The Basics
At the core of Python (and any programming language) there are some key characteristics of how a program is structured that enable the proper execution of that program. These characteristics include the structure of the code itself, the core data types from which others are built, and core operators that modify objects or create new ones. From these raw materials more complex commands, functions, and modules are built.
For guidance on recommended Python structure refer to the Python Style Guide.
Examples
Step1:  Try It Yourself
Go to the section 4.4. Numeric Types in the Python 3 documentation at https
Step2:  Variables can be reassigned
Step3:  The ability to reassign variable values becomes important when iterating through groups of objects for batch processing or other purposes. In the example below, the value of b is dynamically updated every time the while loop is executed
Step4:  Variable data types can be inferred, so Python does not require us to declare the data type of a variable on assignment.
Step5:  is equivalent to
Step6:  There are cases when we may want to declare the data type, for example to assign a different data type from the default that will be inferred. Concatenating strings provides a good example.
Step7:  Above, Python has inferred the type of the variable pizza to be an integer. Since strings can only be concatenated with other strings, our print statement generates an error. There are two ways we can resolve the error
Step8:  Given the following variable assignments
Step9:  Structure
Now that we have practiced assigning variables and reading information from files, we will have a look at concepts that are key to developing processes to use and analyze this information.
Blocks
The structure of a Python program is pretty simple
Step11:  Lists
https
Step12:  There are multiple ways to create a list
Step13:  We can inspect our lists
Step14:  The above output for constructed_list may seem odd. Referring to the documentation, we see that the argument to the type constructor is an iterable, which according to the documentation is "An object capable of returning its members one at a time." In our construtor statement above
```
Using the type constructor
constructed_list = list('purple')
```
the word 'purple' is the object - in this case a str (string) consisting of the word 'purple' - that when used to construct a list returns its members (individual letters) one at a time.
Compare the outputs below
Step15:  Lists in Python are
Step16:  Info on additional list methods is available at https
<ASSISTANT_TASK:>
Python Code:
# The interpreter can be used as a calculator, and can also echo or concatenate strings.
3 + 3
3 * 3
3 ** 3
3 / 2 # classic division - output is a floating point number
# Use quotes around strings, single or double, but be consistent to the extent possible
'dogs'
"dogs"
"They're going to the beach"
'He said "I like mac and cheese"'
# sometimes you can't escape the escape
'He said "I\'d like mac and cheese"'
# + operator can be used to concatenate strings
'dogs' + "cats"
print('Hello World!')
Explanation: The Basics
At the core of Python (and any programming language) there are some key characteristics of how a program is structured that enable the proper execution of that program. These characteristics include the structure of the code itself, the core data types from which others are built, and core operators that modify objects or create new ones. From these raw materials more complex commands, functions, and modules are built.
For guidance on recommended Python structure refer to the Python Style Guide.
Examples: Variables and Data Types
The Interpreter
End of explanation
a = 5
b = 10
a + b
Explanation: Try It Yourself
Go to the section 4.4. Numeric Types in the Python 3 documentation at https://docs.python.org/3.4/library/stdtypes.html. The table in that section describes different operators - try some!
What is the difference between the different division operators (/, //, and %)?
Variables
Variables allow us to store values for later use.
End of explanation
b = 38764289.1097
a + b
Explanation: Variables can be reassigned:
End of explanation
a = 5
b = 10
while b > a:
    print("b="+str(b))
    b = b-1
Explanation: The ability to reassign variable values becomes important when iterating through groups of objects for batch processing or other purposes. In the example below, the value of b is dynamically updated every time the while loop is executed:
End of explanation
a = 5
type(a)
Explanation: Variable data types can be inferred, so Python does not require us to declare the data type of a variable on assignment.
End of explanation
a = int(5)
type(a)
c = 'dogs'
print(type(c))
c = str('dogs')
print(type(c))
Explanation: is equivalent to
End of explanation
customer = 'Carol'
pizzas = 2
print(customer + ' ordered ' + pizzas + ' pizzas.')
Explanation: There are cases when we may want to declare the data type, for example to assign a different data type from the default that will be inferred. Concatenating strings provides a good example.
End of explanation
customer = 'Carol'
pizzas = str(2)
print(customer + ' ordered ' + pizzas + ' pizzas.')
customer = 'Carol'
pizzas = 2
print(customer + ' ordered ' + str(pizzas) + ' pizzas.')
Explanation: Above, Python has inferred the type of the variable pizza to be an integer. Since strings can only be concatenated with other strings, our print statement generates an error. There are two ways we can resolve the error:
Declare the pizzas variable as type string (str) on assignment or
Re-cast the pizzas variable as a string within the print statement.
End of explanation
# Read unstructured text
# One way is to open the whole file as a block
file_path = "./beowulf" # We can save the path to the file as a variable
file_in = open(file_path, "r") # Options are 'r', 'w', and 'a' (read, write, append)
beowulf_a = file_in.read()
file_in.close()
print(beowulf_a)
# Another way is to read the file as a list of individual lines
with open(file_path, "r") as b:
    beowulf_b = b.readlines()
print(beowulf_b)
# In order to get a similar printout to the first method, we use a for loop
# to print line by line - more on for loops below!
for l in beowulf_b:
    print(l)
# We now have two variables with the content of our 'beowulf' file represented using two different data structures.
# Why do you think we get the different outputs from the next two statements?
# Beowulf text stored as one large string
print("As string:", beowulf_a[0])
# Beowulf text stored as a list of lines
print("As list of lines:", beowulf_b[0])
# We can confirm our expectations by checking on the types of our two beowulf variables
print(type(beowulf_a))
print(type(beowulf_b))
# Read CSV files using the Pandas read_csv method.
# Note: Pandas also includes methods for reading Excel.
# First we need to import the pandas library
import pandas as pd
# Create a variable to hold the path to the file
fpath = "aaj1945_DataS1_Egg_shape_by_species_v2.csv"
egg_data = pd.read_csv(fpath)
# We can get all kinds of info about the dataset
# info() provides an overview of the structure
print(egg_data.info())
# Look at the first five rows
egg_data.head()
# Names of columns
print(egg_data.columns.values)
# Dimensions (number of rows and columns)
print(egg_data.shape)
# And much more! But as a final example we can perform operations on the data.
# Descriptive statistics on the "Number of eggs" column
print(egg_data["Number of eggs"].describe())
# Or all of the columns in whole table with numeric data types:
print(egg_data.describe())
Explanation: Given the following variable assignments:
x = 12
y = str(14)
z = donuts
Predict the output of the following:
y + z
x + y
x + int(y)
str(x) + y
Check your answers in the interpreter.
Variable Naming Rules
Variable names are case senstive and:
Can only consist of one "word" (no spaces).
Must begin with a letter or underscore character ('_').
Can only use letters, numbers, and the underscore character.
We further recommend using variable names that are meaningful within the context of the script and the research.
Reading Files
We can accomplish a lot by assigning variables within our code as demonstrated above, but often we are interested in working with objects and data that exist in other files and directories on our system.
When we want to read data files into a script, we do so by assigning the content of the file to a variable. This stores the data in memory and lets us perform processes and analyses on the data without changing the content of the source file.
There are several ways to read files in Python - many libraries have methods for reading text, Excel and Word documents, PDFs, etc. This morning we're going to demonstrate using the read() and readlines() method in the standard library, and the Pandasread_csv() function.
End of explanation
# Fun with types
this = 12
that = 15
the_other = "27"
my_stuff = [this,that,the_other,["a","b","c",4]]
more_stuff = {
    "item1": this, 
    "item2": that, 
    "item3": the_other, 
    "item4": my_stuff
}
this + that
# this won't work ...
# this + that + the_other
# ... but this will ...
this + that + int(the_other)
# ...and this too
str(this) + str(that) + the_other
Explanation: Structure
Now that we have practiced assigning variables and reading information from files, we will have a look at concepts that are key to developing processes to use and analyze this information.
Blocks
The structure of a Python program is pretty simple:
Blocks of code are defined using indentation. Code that is at a lower level of indentation is not considerd part of a block. Indentation can be defined using spaces or tabs (spaces are recommended by the style guide), but be consistent (and prepared to defend your choice). As we will see, code blocks define the boundaries of sets of commands that fit within a given section of code. This indentation model for defining blocks of code significantly increases the readabiltiy of Python code.
For example:
&gt;&gt;&gt;a = 5
&gt;&gt;&gt;b = 10
&gt;&gt;&gt;while b &gt; a:
...    print("b="+str(b))
...    b = b-1
&gt;&gt;&gt;print("I'm outside the block")
Comments & Documentation
You can (and should) also include documentation and comments in the code your write - both for yourself, and potential future users (including yourself). Comments are pretty much any content on a line that follows a # symbol (unless it is between quotation marks. For example:
&gt;&gt;&gt;# we're going to do some math now
&gt;&gt;&gt;yae = 5                   # the number of votes in favor
&gt;&gt;&gt;nay = 10                  # the number of votes against
&gt;&gt;&gt;proportion = yae / nay    # the proportion of votes in favor
&gt;&gt;&gt;print(proportion)
When you are creating functions or classes (a bit more on what these are in a bit) you can also create what are called doc strings that provide a defined location for content that is used to generate the help() information highlighted above and is also used by other systems for the automatic generation of documentation for packages that contain these doc strings. Creating a doc string is simple - just create a single or multi-line text string (more on this soon) that starts on the first indented line following the start of the definition of the function or class. For example:  
&gt;&gt;&gt;# we're going to create a documented function and then access the information about the function
&gt;&gt;&gt;def doc_demo(some_text="Ill skewer yer gizzard, ye salty sea bass"):
...    This function takes the provided text and prints it out in Pirate
...    
...    If a string is not provided for `some_text` a default message will be displayed
...    
...    out_string = "Ahoy Matey. " + some_text
...    print(out_string)
&gt;&gt;&gt;help(doc_demo)
&gt;&gt;&gt;doc_demo()
&gt;&gt;&gt;doc_demo("Sail ho!")
Standard Objects
Any programming language has at its foundation a collection of types or in Python's terminology objects. The standard objects of Python consist of the following:
Numbers - integer, floating point, complex, and multiple-base defined numeric values
Strings - immutable strings of characters, numbers, and symbols that are bounded by single- or double-quotes
Lists - an ordered collection of objects that is bounded by square-brackets - []. Elements in lists are extracted or referenced by their position in the list. For example, my_list[0] refers to the first item in the list, my_list[5] the sixth, and my_list[-1] to the last item in the list. 
Dictionaries -  an unordered collection of objects that are referenced by keys that allow for referring to those objexts by reference to those keys. Dictionaries are bounded by curley-brackets - {} with each element of the dictionary consisting of a key (string) and a value (object) separated by a colon :. Elements of a dictionary are extracted or referenced using their keys. for example:
my_dict = {"key1":"value1", "key2":36, "key3":[1,2,3]}
my_dict['key1'] returns "value1"
my_dict['key3'] returns [1,2,3]
Tuples - immutable lists that are bounded by parentheses = (). Referencing elements in a tuple is the same as referencing elements in a list above. 
Files - objects that represent external files on the file system. Programs can interact with (e.g. read, write, append) external files through their representative file objects in the program.
Sets - unordered, collections of immutable objects (i.e. ints, floats, strings, and tuples) where membership in the set and uniqueness within the set are defining characteristics of the member objects. Sets are created using the set function on a sequence of objects. A specialized list of operators on sets allow for identifying union, intersection, and difference (among others) between sets. 
Other core types - Booleans, types, None
Program unit types - functions, modules, and classes for example
Implementation-related types (not covered in this workshop)
These objects have their own sets of related methods (as we saw in the help() examples above) that enable their creation, and operations upon them.
End of explanation
# Separate list items with commas!
number_list = [1, 2, 3, 4, 5]
string_list = ['apples', 'oranges', 'pears', 'grapes', 'pineapples']
combined_list = [1, 2, 'oranges', 3.14, 'peaches', 'grapes', 99.19876]
# Nested lists - lists of lists - are allowed.
list_of_lists = [[1, 2, 3], 
                 ['oranges', 'grapes', 8], 
                 [['small list'], 
                  ['bigger', 'list', 55], 
                  ['url_1', 'url_2']
                 ]
                ]
Explanation: Lists
https://docs.python.org/3/library/stdtypes.html?highlight=lists#list
Lists are a type of collection in Python. Lists allow us to store sequences of items that are typically but not always similar. All of the following lists are legal in Python:
End of explanation
# Create an empty list
empty_list = []
# As we did above, by using square brackets around a comma-separated sequence of items
new_list = [1, 2, 3]
# Using the type constructor
constructed_list = list('purple')
# Using a list comprehension
result_list = [i for i in range(1, 20)]
Explanation: There are multiple ways to create a list:
End of explanation
empty_list
new_list
result_list
constructed_list
Explanation: We can inspect our lists:
End of explanation
constructed_list_int = list(123)
constructed_list_str = list('123')
constructed_list_str
Explanation: The above output for constructed_list may seem odd. Referring to the documentation, we see that the argument to the type constructor is an iterable, which according to the documentation is "An object capable of returning its members one at a time." In our construtor statement above
```
Using the type constructor
constructed_list = list('purple')
```
the word 'purple' is the object - in this case a str (string) consisting of the word 'purple' - that when used to construct a list returns its members (individual letters) one at a time.
Compare the outputs below:
End of explanation
ordered = [3, 2, 7, 1, 19, 0]
ordered
# There is a 'sort' method for sorting list items as needed:
ordered.sort()
ordered
Explanation: Lists in Python are:
mutable - the list and list items can be changed
ordered - list items keep the same "place" in the list
Ordered here does not mean sorted. The list below is printed with the numbers in the order we added them to the list, not in numeric order:
End of explanation
string_list = ['apples', 'oranges', 'pears', 'grapes', 'pineapples']
string_list[0]
# We can use positions to 'slice' or select sections of a list:
string_list[3:]           # start at index '3' and continue to the end
string_list[:3]           # start at index '0' and go up to, but don't include index '3'
string_list[1:4]          # start at index '1' and go up to and don't include index '4'
# If we don't know the position of a list item, we can use the 'index()' method to find out.
# Note that in the case of duplicate list items, this only returns the position of the first one:
string_list.index('pears')
string_list.append('oranges')
string_list
string_list.index('oranges')
# one more time with lists and dictionaries
list_ex1 = my_stuff[0] + my_stuff[1] + int(my_stuff[2])
print(list_ex1)
# we can use parentheses to split a continuous group of commands over multiple lines
list_ex2 = (
    str(my_stuff[0]) 
    + str(my_stuff[1]) 
    + my_stuff[2] 
    + my_stuff[3][0]
)
print(list_ex2)
dict_ex1 = (
    more_stuff['item1']
    + more_stuff['item2']
    + int(more_stuff['item3'])
)
print(dict_ex1)
dict_ex2 = (
    str(more_stuff['item1'])
    + str(more_stuff['item2'])
    + more_stuff['item3']
)
print(dict_ex2)
# Now try it yourself ...
# print out the phrase "The answer: 42" using the following 
# variables and one or more of your own and the 'print()' function
# (remember spaces are characters as well)
start = "The"
answer = 42
Explanation: Info on additional list methods is available at https://docs.python.org/3/library/stdtypes.html?highlight=lists#mutable-sequence-types
Because lists are ordered, it is possible to access list items by referencing their positions. Note that the position of the first item in a list is 0 (zero), not 1!
End of explanation
<END_TASK>