<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Scientific Computing with Python
This is a course about applying computer programming to problems of modeling physical systems and analysing data related to those systems. We'll be using a programming language called "Python 3". The first project is a "getting started" experience where you start to use the programming environment, become familiar with the basic elements of the language and, more or less, "learn your way around." Let's get started!
Installing/Accessing Python/Jupyter Notebook
The most reliable method of setting up an environment on your local computer is to use Anaconda. This will work and allow you to write code even without an internet connection. Unfortuantely it's not as convenient for collaborative work. For collaboration the easiest approach is to use deepnote. Finally, an option that works well with Google Drive is Google's own "colab" which works OK, but it's not as good with real-time interactive collaboration.
Notebook UI + Help
Before we get too far, first click on the "Help" menu and choose "User Interface Tour" and then "Keyboard Shortcuts". Look over these and remember where they are if you get stuck. You'll also see that under the "Help" menu there are links to module specific help sites for all the major python packages we'll be using this semester.
Built in types
First things first. Python comes with many "built in" types. These are things like integers, floating point numbers, srings, tuples, lists and dictionaries. Let's go over those one at a time. 
Integers and floats are easy
Step1:  Like most programming languages you can operate on these values using unary and binary operators, like so
Step2:  Tuples and Lists
These guys are used to track collections of things. For example you can have a list of integers like so
Step3:  The difference between these guys is that a list is 'mutable' and a tuple is not. In other words you can change a list by inserting, appending and deleting elements of the list, but a tuple, once born, cannot be modified.
Step4:  Items within Tuples and lists can be accessed using their "index". Note that index values start at "0"
Step5:  Note
Step6:  Strings
A string is a collection of characters, which like a list can be indexed, but has extra methods that only make sense for strings. We use string to manage textual data.
Step8:  String methods
You can manipulate strings by using built-in methods of string objects like so
Step9:  Dictionaries
A dictionary is a structured type, similar a list in that it can be indexed, but not ordered like a list
Step10:  import this
While you can do a lot with built-in python types, for many things we have to do in scientific computing it makes sense to import additional functionality using an "import" statement. Let's import the Pandas libaray using the python import statment
Step11:  The most important object defined in pandas is the DataFrame. Here's one way to create a DataFrame with pandas using a dictionary
Step12:  This creates a DataFrame with two "Columns" x and y. You can fetch the columns individually
Step13:  Logic and Loops
It's hard to do much without loops sooner or later! There are two basic types of loops in python "for" and "while". The while loop executes the statements within it's scope until a logical expression becomes False. A for loop executes the statements within it's scope for every element of a sequence (e.g., a list, tuple, or any other sequence type). Basically if you have a sequence you need to iterate over, use a for loop. On the other hand, if you want to iterate until some condition is met, then use a while.
Here's an example
Step14:  Functions
We often need to encapsulate code so that it can be easily re-used. This is a part of breaking down problems into smaller parts that are more manageable. Functions are easy to define in python, the basic syntax is
<ASSISTANT_TASK:>
Python Code:
#
# When the cursor is in this cell hit "shift enter" to execute the python code here
#
x=3     # x is assigned an integer value of 3
y=2.4   # y is assigned a floating point value of 2.4
print("x and y are:", x, 'and',y)
Explanation: Scientific Computing with Python
This is a course about applying computer programming to problems of modeling physical systems and analysing data related to those systems. We'll be using a programming language called "Python 3". The first project is a "getting started" experience where you start to use the programming environment, become familiar with the basic elements of the language and, more or less, "learn your way around." Let's get started!
Installing/Accessing Python/Jupyter Notebook
The most reliable method of setting up an environment on your local computer is to use Anaconda. This will work and allow you to write code even without an internet connection. Unfortuantely it's not as convenient for collaborative work. For collaboration the easiest approach is to use deepnote. Finally, an option that works well with Google Drive is Google's own "colab" which works OK, but it's not as good with real-time interactive collaboration.
Notebook UI + Help
Before we get too far, first click on the "Help" menu and choose "User Interface Tour" and then "Keyboard Shortcuts". Look over these and remember where they are if you get stuck. You'll also see that under the "Help" menu there are links to module specific help sites for all the major python packages we'll be using this semester.
Built in types
First things first. Python comes with many "built in" types. These are things like integers, floating point numbers, srings, tuples, lists and dictionaries. Let's go over those one at a time. 
Integers and floats are easy:
End of explanation
z=x+y
print("The value of z is:", z)
Explanation: Like most programming languages you can operate on these values using unary and binary operators, like so:
End of explanation
aList = [1,2,9,4,7]
print("We have a list:", aList, "with a length of:", len(aList))
aTuple = (1,2,9,4,7)
print("We have a tuple:", aTuple, "with a length of:", len(aTuple))
Explanation: Tuples and Lists
These guys are used to track collections of things. For example you can have a list of integers like so:
End of explanation
aList.append(17)
print("We now have a modified list:", aList, "with a length of ", len(aList))
aTuple.append(12) # this will fail! You can't append to a tuple.
Explanation: The difference between these guys is that a list is 'mutable' and a tuple is not. In other words you can change a list by inserting, appending and deleting elements of the list, but a tuple, once born, cannot be modified.
End of explanation
print("element 3 of the list is", aList[3])
print("element 27 of the tuple is", aTuple[27]) # this will fail! There is no such element.
Explanation: Items within Tuples and lists can be accessed using their "index". Note that index values start at "0":
End of explanation
print(aList*3)
print(aTuple*4)
Explanation: Note: When you "multiply" a list or a tuple by an integer you get copies of the original:
End of explanation
aString = "hello there world!"
print("We have a string:", aString, "whose length is:", len(aString))
print("the 9th element of aString is", aString[9])
Explanation: Strings
A string is a collection of characters, which like a list can be indexed, but has extra methods that only make sense for strings. We use string to manage textual data.
End of explanation
print(aString.split()) # split a string on spaces, convert to a list
bString=1,2,3,4
5,6,7,8
9,10,11,12
print("Here's what bString looks like:", repr(bString))
print("Let's split the lines:", bString.splitlines())
print(aString.upper())
Explanation: String methods
You can manipulate strings by using built-in methods of string objects like so:
End of explanation
aDict = {'a':1, 'b':"sam", 'joe':3.1415927}
print("We have a dictionary with keys:", aDict.keys())
print("It as values:", aDict.values())
print("And items:", aDict.items())
print("You can index it like an array:", aDict['joe'])
Explanation: Dictionaries
A dictionary is a structured type, similar a list in that it can be indexed, but not ordered like a list:
End of explanation
# tell the plotting system that we want plots inside the notebook
%matplotlib inline   
import pandas as pd  # we're renaming pandas as 'pd' here to save typing
Explanation: import this
While you can do a lot with built-in python types, for many things we have to do in scientific computing it makes sense to import additional functionality using an "import" statement. Let's import the Pandas libaray using the python import statment:
End of explanation
myDF = pd.DataFrame({'x':[1,2,3,4,5], 'y':[9,8,7,6,5]})
Explanation: The most important object defined in pandas is the DataFrame. Here's one way to create a DataFrame with pandas using a dictionary:
End of explanation
print("Here is x:", myDF.x.values)
print("Here is y:", myDF.y.values)
#
# It is possible to plot directly from the DataFrame
#
myDF.plot('x','y')
Explanation: This creates a DataFrame with two "Columns" x and y. You can fetch the columns individually:
End of explanation
print("Starting with:", repr(bString)) # show the raw string
for s in bString.splitlines():
    print("Breaking down the string:", s)
    for n in s.split(','):
        print("Found the item:", n)
#
# another way with the while loop
#
cList=bString.splitlines()
while len(cList)>0:
    s=cList.pop(0) # pop off the zeroth element of the list
    for n in s.split(','):
        print("Found item:", n)
        
Explanation: Logic and Loops
It's hard to do much without loops sooner or later! There are two basic types of loops in python "for" and "while". The while loop executes the statements within it's scope until a logical expression becomes False. A for loop executes the statements within it's scope for every element of a sequence (e.g., a list, tuple, or any other sequence type). Basically if you have a sequence you need to iterate over, use a for loop. On the other hand, if you want to iterate until some condition is met, then use a while.
Here's an example:
End of explanation
def myFunction(x):        # function to compute 1.0/(x**2 + 1.0)
    aLocalVar = x*x+1.0   # this is x**2 + 1.0
    return 1.0/aLocalVar  # finally 1.0/(x**2 + 1.0)
for i in range(10):
    print("i=",i,"myFunction(i):", myFunction(i))
    
Explanation: Functions
We often need to encapsulate code so that it can be easily re-used. This is a part of breaking down problems into smaller parts that are more manageable. Functions are easy to define in python, the basic syntax is:
End of explanation
<END_TASK>