<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Discussion 1
Step1:  Why do we get the answer above rather than what we would expect?
The answer has to do with the type of number being used.  Python is a "dynamically" typed language and automatically determines what kind of number to allocate for us.  Above, because we did not include a decimal, Python automatically treated the expression as integers (int type) and according to integer arithmetic, 1 / 2 = 0.  Now if we include a decimal we get
Step2:  Note that Python will make the output a float in this case.  What happens for the following though?
Step3:  Good practice to just add a decimal after any number you really want to treat as a float.
Additional types of numbers include complex, Decimal and Fraction.
Step4:  Note that to use "named" functions such as sqrt or sin we need to import a module so that we have access to those functions.  When you import a module (or package) in Python we are asking Python to go look for the code that is named and make them active in our workspace (also called a namespace in more general parlance).  Here is an example where we use Python's builtin math module
Step5:  Note that in order to access these functions we need to prepend the math. to the functions and the constant $\pi$.  We can forgo this and import all of what math holds if we do the following
Step6:  Note that many of these functions always return a float number regardless of their input.
Variables
Assign variables like you would in any other language
Step7:  Note that we do not get what we expect from this expression as we expected from above.  What would we have to change to get this to work?
We could go back to change our initializations but we could also use the function float to force these values to be of float type
Step8:  Note here we have left the defined variables as integers as it makes sense that they remain that way (fractional students aside).
Step9:  Lists
One of the most useful data structures in Python is the list.
Step10:  Lists are defined with square brackets and delineated by commas.  Note that there is another data type called sequences denoted by ( ) which are immutable (cannot be changed) once created.  Lets try to do some list manipulations with our list of grades above.
Access a single value in a list
Step11:  Note that Python is 0 indexed, i.e. the first value in the list is accessed by 0.
Find the length of a list
Step12:  Add values to a list
Step13:  Slicing is another important operation
Step14:  Note that the range of values does not include the last indexed!  This is important to remember for more than lists but we will get to that later.
Step15:  Another property of lists is that you can put different types in them at the same time.  This can be important to remember if you may have both int and float types.
Step16:  Finally, one of the more useful list creation functions is range which creates a list with the bounds requested
Step17:  Control Flow
if
Most basic logical control
Step18:  for
The for statements provide the most common type of loops in Python (there is also a while construct).
Step19:  Related to the for statement are the control statements break and continue.  Ideally we can create a loop with logic that can avoid these but sometimes code can be more readable with judiciuos use of these statements.
Step20:  The pass statement might appear fairly useless as it simply does nothing but can provide a stub to remember to come back and implement something
Step21:  Defining Functions
The last statement above defines a function in Python with an argument called x.  Functions can be defined and do lots of different things, here are a few examples.
Step23:  Lets try writing a bit more of a complex (and useful) function.  The Fibinocci sequence is formed by adding the previous two numbers of the sequence to get the next value (starting with [0, 1]).
<ASSISTANT_TASK:>
Python Code:
2 + 2
32 - (4 + 2)**2
1 / 2
Explanation: Discussion 1:  Introduction to Python
So you want to code in Python?  We will do some basic manipulations and demonstrate some of the basics of the notebook interface that we will be using extensively throughout the course.
Topics:
 - Math
 - Variables
 - Lists
 - Control flow
 - Coding style
 - Other data structures
 - IPython/Jupyter notebooks
Other intros: 
 - Basic Python
 - Software Carpentry - Programming in Python
Python Math
Lets start with some basic functions:
End of explanation
1.0 / 2
Explanation: Why do we get the answer above rather than what we would expect?
The answer has to do with the type of number being used.  Python is a "dynamically" typed language and automatically determines what kind of number to allocate for us.  Above, because we did not include a decimal, Python automatically treated the expression as integers (int type) and according to integer arithmetic, 1 / 2 = 0.  Now if we include a decimal we get:
End of explanation
4.0 + 4**(3/2)
4.0 + 4.0**(3.0 / 2.0)
Explanation: Note that Python will make the output a float in this case.  What happens for the following though?
End of explanation
3+5j
Explanation: Good practice to just add a decimal after any number you really want to treat as a float.
Additional types of numbers include complex, Decimal and Fraction.
End of explanation
import math
math.sqrt(4)
math.sin(math.pi / 2.0)
math.exp(-math.pi / 4.0)
Explanation: Note that to use "named" functions such as sqrt or sin we need to import a module so that we have access to those functions.  When you import a module (or package) in Python we are asking Python to go look for the code that is named and make them active in our workspace (also called a namespace in more general parlance).  Here is an example where we use Python's builtin math module:
End of explanation
from math import *
sin(pi / 2.0)
Explanation: Note that in order to access these functions we need to prepend the math. to the functions and the constant $\pi$.  We can forgo this and import all of what math holds if we do the following:
End of explanation
num_students = 80
room_capacity = 85
(room_capacity - num_students) / room_capacity * 100.0
Explanation: Note that many of these functions always return a float number regardless of their input.
Variables
Assign variables like you would in any other language:
End of explanation
float(room_capacity - num_students) / float(room_capacity) * 100.0
Explanation: Note that we do not get what we expect from this expression as we expected from above.  What would we have to change to get this to work?
We could go back to change our initializations but we could also use the function float to force these values to be of float type:
End of explanation
a = 10
b = a + 2
print b
Explanation: Note here we have left the defined variables as integers as it makes sense that they remain that way (fractional students aside).
End of explanation
grades = [90.0, 67.0, 85.0, 76.0, 98.0, 70.0]
Explanation: Lists
One of the most useful data structures in Python is the list.
End of explanation
grades[3]
Explanation: Lists are defined with square brackets and delineated by commas.  Note that there is another data type called sequences denoted by ( ) which are immutable (cannot be changed) once created.  Lets try to do some list manipulations with our list of grades above.
Access a single value in a list
End of explanation
len(grades)
Explanation: Note that Python is 0 indexed, i.e. the first value in the list is accessed by 0.
Find the length of a list
End of explanation
grades = grades + [62.0, 82.0, 59.0]
print grades
Explanation: Add values to a list
End of explanation
grades[2:5]
grades[0:4]
grades[:4]
grades[4:]
Explanation: Slicing is another important operation
End of explanation
grades[4:11]
Explanation: Note that the range of values does not include the last indexed!  This is important to remember for more than lists but we will get to that later.
End of explanation
remember = ["2", 2, 2.0]
remember[0] / 1
remember[1] / 1
remember[2] / 1
Explanation: Another property of lists is that you can put different types in them at the same time.  This can be important to remember if you may have both int and float types.
End of explanation
count = range(3,7)
print count
Explanation: Finally, one of the more useful list creation functions is range which creates a list with the bounds requested
End of explanation
x = 4
if x > 5:
    print "x is greater than 5"
elif x < 5:
    print "x is less than 5"
else:
    print "x is equal to 5"
    
Explanation: Control Flow
if
Most basic logical control
End of explanation
for i in range(5):
    print i
for i in range(3,7):
    print i
for animal in ['cat', 'dog', 'chinchilla']:
    print animal
Explanation: for
The for statements provide the most common type of loops in Python (there is also a while construct).
End of explanation
for n in range(2, 10):
    is_prime = True
    for x in range(2, n):
        if n % x == 0:
            print n, 'equals', x, '*', n / x
            is_prime = False
            break
    if is_prime:
        print "%s is a prime number" % (n)
Explanation: Related to the for statement are the control statements break and continue.  Ideally we can create a loop with logic that can avoid these but sometimes code can be more readable with judiciuos use of these statements.
End of explanation
def my_func(x):
    # Remember to implement this later!
    pass
Explanation: The pass statement might appear fairly useless as it simply does nothing but can provide a stub to remember to come back and implement something
End of explanation
def my_print_function(x):
    print x
my_print_function(3)
def my_add_function(a, b):
    return a + b
my_add_function(3.0, 5.0)
def my_crazy_function(a, b, c=1.0):
    d = a + b**c
    return d
my_crazy_function(2.0, 3.0), my_crazy_function(2.0, 3.0, 2.0), my_crazy_function(2.0, 3.0, c=2.0)
def my_other_function(a, b, c=1.0):
    return a + b, a + b**c, a + b**(3.0 / 7.0)
my_other_function(2.0, 3.0, c=2.0)
Explanation: Defining Functions
The last statement above defines a function in Python with an argument called x.  Functions can be defined and do lots of different things, here are a few examples.
End of explanation
def fibonacci(n):
    Return a list of the Fibonacci sequence up to n
    values = [0, 1]
    while values[-1] <= n:
        values.append(values[-1] + values[-2])
        print values
    return values
fibonacci(100)
Explanation: Lets try writing a bit more of a complex (and useful) function.  The Fibinocci sequence is formed by adding the previous two numbers of the sequence to get the next value (starting with [0, 1]).
End of explanation
<END_TASK>