<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 A crash course in Python
<p>**Authors**
Step1:  <span style="color
Step2:  <span style="color
Step3:  Python's built-in mathematical operators include +, -, *, **, for exponentiation, / for division, // for integer division (without rest), % for division but giving you the rest.
<span style="color
Step4:  And here is how to use an existing variable
Step5:  <span style="color
Step6:  When a command requires input arguments, as for math.sqrt(put a number here), a handy keyboard shortcut is Shift-Tab.
A tooltip will light up showing you the various arguments you can pass to the command.
<span style="color
Step7:  Note how we used the # character to write comments. Whereas Python discards the comments completely, adding comments in the code is important when the code is to be read by other humans (including yourself in the future).
<span style="color
Step8:  Python tries to tell you where it stopped understanding, but in the above examples, each program is only 1 line long.
It also tries to show you where on the line the problem happened with caret ("^").
Finally it tells you the type of thing that went wrong, (NameError, SyntaxError, ZeroDivisionError) and a bit more information like "name 'gibberish' is not defined" or "unexpected EOF while parsing".
Unfortunately you might not find "unexpected EOF while parsing" too helpful. EOF stands for End of File, but what file? What is parsing? Python does it's best, but it does take a bit of time to develop a knack for what these messages mean. If you run into an error you don't understand please ask a tutor.
Types of variables in python
When you define a variable in python it has a type. Above we dealt with numbers which are of type ... Below we briefly introduce the other types you might see in the rest of the tutorial. 
Simply put there is text, i.e. strings, and two kinds of containers, e.g. lists and dictionaries. 
All together now
An example for each of the most important types in python
Step9:  The Written Word, i.e. strings
Numbers are great... but most of our day to day computing needs involves text, from emails to tweets to documents. Or in biology
Step10:  Strings are surrounded by quotes. Without the quotes Hello by itself would be viewed as a variable name.
You can use either double quotes (") or single quotes (') for text/strings. As we saw before we can also save text in variables.
Let's use strings with variables!
Step11:  Strings in Python are a bit more complicated because the operations on them aren't just + and * (though those are valid operations).
Dot notation and object oriented programming
Python, like many programming languages, supports Object Oriented Programming or OOP for short. In this paradigm, we approach ideas as Objects much as we do in the real world. Each Object is an instance of a Class or a type of object. Such an object may have certain properties or function that can be applied to them. 
So what does all this have to do with dot notation? Dot notation allows us to tell a instance of a class to use one of the functions inside that class. That is why we access the sqrt function from the math module with the dot. And why we access the 'upper' function of a string as my_string.upper()
<span style="color
Step12:  Lists
A list contains a sequence of items. You can concisely instruct Python to perform repeated actions on the elements of a list. Let's first create a list of numbers
Step13:  Note the syntax we used to create the list
Step14:  Now, let's compute the sum of all elements in the list. Python provides a built-in function for this
Step15:  We can also access individual elements in the list, using the following syntax
Step16:  Note that indexing starts at 0 in Python
Step17:  We can access sublists with the following syntax
Step18:  Here, 1
Step19:  The keys in a dictionary can be anything including numbers
Step20:  <span style="color
Step21:  Note that the for loop steps in sequence through the numbers in the list. 
Every loop, the variable number is assigned the value of the next number in the list
You may call this variable number whatever you wish. As long as you also change it in the third line
As a more complex example, we can also loop over the keys of a dictionary.
Step22:  There are several things to note here
Step23:  This is called a list comprehension. A new list is created here; it contains the squares of all numbers in the list. This concise syntax leads to highly readable and Pythonic code.
<span style="color
<ASSISTANT_TASK:>
Python Code:
# ignore the first two lines: they allow you to show multiple outputs per cell
from IPython.core.interactiveshell import InteractiveShell
InteractiveShell.ast_node_interactivity = "all" 
import this
Explanation: A crash course in Python
<p>**Authors**: Thierry D.G.A Mondeel, Stefania Astrologo, Ewelina Weglarz-Tomczak & Hans V. Westerhoff <br/>
University of Amsterdam <br/>2017
</p>
Inspired in part by a collection of parts from various notebooks on the web. Some links to the originals provided below:
Learning IPython for Interactive Computing and Data Visualization, second edition.**
https://github.com/rajathkumarmp/Python-Lectures
http://nbviewer.jupyter.org/urls/bitbucket.org/amjoconn/watpy-learning-to-code-with-python/raw/3441274a54c7ff6ff3e37285aafcbbd8cb4774f0/notebook/Learn%20to%20Code%20with%20Python.ipynb
Note: The goal here is not to give you a complete introduction to python. There are separete university courses for this that fill a semester. We just want you to be familiar enough to be able to interact with prewritten code to do FBA calculations later on in the tutorial.
Some motivation
Python in Computational Biology: or why you should care about python
Its what we chose to use in this tutorial
Python is a modern programming language developed in the early 1990s by Guido van Rossum -> A Dutch guy! (https://en.wikipedia.org/wiki/Guido_van_Rossum) 
Beginner Friendly
Easy to understand and read
It's free
It is pervasive in computational biology 
All you need to know
Some words of wisdom by Tim Peters, i.e. the Zen of Python.
End of explanation
print("The classic view of the central dogma of biology states that \
'the coded genetic information hard-wired into DNA is transcribed into \
individual transportable cassettes, composed of messenger RNA (mRNA); \
each mRNA cassette contains the program for synthesis of a particular \
protein (or small number of proteins).'")
Explanation: <span style="color:red">Assignment (lifelong):</span> Which of these (do not) apply to science as well? Or even, dare we say, to life in general?
Printing text in python
End of explanation
2 * 2
3/2
3//2
6%2
8%3
2**5
Explanation: <span style="color:red">Assignment (1 min):</span> print the name of your favorite protein below. 
Congratulations! You are now a Python programmer.
Numbers matter in biology
Luckily we can use Python as a calculator.
Below we show some examples. Do you understand what each one does? 
TIP (Division): In Python 3, 3 / 2 returns 1.5 (floating-point division). 3 // 2 for integer division.
End of explanation
avogadro = 6e23
print('How many molecules are contained in a mole? Answer:',avogadro,'molecules.')
Explanation: Python's built-in mathematical operators include +, -, *, **, for exponentiation, / for division, // for integer division (without rest), % for division but giving you the rest.
<span style="color:red">Assignment (1 min):</span> Experiment with these a bit
See: http://bionumbers.hms.harvard.edu/KeyNumbers.aspx
According to bionumbers (see link) e. coli has a volume of up to $5~\mu m^3$ and yeast has a volume of up to $160~\mu m^3$
<span style="color:red">Assignment (3 min):</span> Calculate in the cell below how many times bigger the volume of yeast is compared to e. coli.
<span style="color:red">Assignment (3 min):</span> Using the bionumbers page find the "water molecule diameter" and the diameter of a yeast cell. Then calculate how many water molecules you could theoretically lay side by side in a yeast cell.
Variables
form a fundamental concept of any programming language. A variable has a name and a value. Here is how to create a new variable in Python:
End of explanation
print('How many molecules in a 2 moles? Answer:',2*avogadro,'molecules')
Explanation: And here is how to use an existing variable:
End of explanation
import math # load some common mathematical operations
?math.sqrt(2)
Explanation: <span style="color:red">Assignment (1 min):</span> Calculate and print the number of molecules in $0.33~\mu M/L$
Getting help in the notebook
When you want to know what a command or function does you can type a question mark in fron of the command.
End of explanation
somefloat = 3.1415
sometext = 'pi is about'  # You can also use double quotes.
print(sometext, somefloat)  # Display several variables.
I_am_true = False
I_am_true 
Explanation: When a command requires input arguments, as for math.sqrt(put a number here), a handy keyboard shortcut is Shift-Tab.
A tooltip will light up showing you the various arguments you can pass to the command.
<span style="color:red">Assignment (2 min):</span> Ask for help on the "math.sqrt" command using the Shift-Tab method described above. Start by typing math.sqrt below and then press Shift-Tab. 
What kind of methods does math contain?
When we import a library like "math", which we did at the top of the notebook, this library will contain many different functions like sqrt above. If you want to find out which ones type "math." (notice the dot!) and then press "TAB". 
<span style="color:red">Assignment (3 min):</span> Use the TAB key to find out some other math functions and play around with them maybe look at the help file.
There are different types of variables. Here, we have used a number (more precisely, an integer). Other important types include floating-point numbers to represent real numbers, strings to represent text, and booleans to represent True/False values. Here are a few examples:
End of explanation
gibberish
*adsflf_
print('Hello'
1v34
2000 / 0
Explanation: Note how we used the # character to write comments. Whereas Python discards the comments completely, adding comments in the code is important when the code is to be read by other humans (including yourself in the future).
<span style="color:red">Assignment (3 min):</span>
Make your own piece of text, i.e. your name and age and print it to the screen. Do not just write a string a text, make your age a variable like pi in the example above. 
Murphy's law: (In a tutorial) Anything that can go wrong will go wrong
Python only understands certain code. When you write something Python doesn't understand it throws an exception and tries to explain what went wrong, but it can only speak in a broken Pythonesque english. Let's see some examples by running these code blocks. This is helpful later on because you will likely encounter (and produce) some errors.
End of explanation
x = 'One definition of systems biology: the study of the interactions between the components of biological systems, \
and how these interactions give rise to the function and behavior of that system (for example, the enzymes and \
metabolites in a metabolic pathway or the heart beats)' # string
print(type(x))
print(x)
print()
x = [0.5,2,24] # list
print(type(x))
print(x)
print('The (rough) cell cycle time of e.coli =',x[0],'hrs, of yeast =',x[1],'hrs, of a human cell',x[2],'hrs')
print()
x = {'e. coli':5,'yeast':12,'human':2.9e3} # dictionary
print(type(x))
print(x)
print('The genome size of e.coli =',x['e. coli'],'Mbp, of yeast =',x['yeast'],'Mbp, of a human cell',x['human'],'Mbp')
Explanation: Python tries to tell you where it stopped understanding, but in the above examples, each program is only 1 line long.
It also tries to show you where on the line the problem happened with caret ("^").
Finally it tells you the type of thing that went wrong, (NameError, SyntaxError, ZeroDivisionError) and a bit more information like "name 'gibberish' is not defined" or "unexpected EOF while parsing".
Unfortunately you might not find "unexpected EOF while parsing" too helpful. EOF stands for End of File, but what file? What is parsing? Python does it's best, but it does take a bit of time to develop a knack for what these messages mean. If you run into an error you don't understand please ask a tutor.
Types of variables in python
When you define a variable in python it has a type. Above we dealt with numbers which are of type ... Below we briefly introduce the other types you might see in the rest of the tutorial. 
Simply put there is text, i.e. strings, and two kinds of containers, e.g. lists and dictionaries. 
All together now
An example for each of the most important types in python
End of explanation
"Hello, World!"
Explanation: The Written Word, i.e. strings
Numbers are great... but most of our day to day computing needs involves text, from emails to tweets to documents. Or in biology: DNA sequences, chemical formulas, hyperlinks between databases etc.
We have already seen a couple strings in Python. Programmers call text strings because they are weird like that. From now on we will only refer to strings, but we just mean pieces of text inside our code.
End of explanation
your_name = "James Watson"
print("Hello,",your_name)
Explanation: Strings are surrounded by quotes. Without the quotes Hello by itself would be viewed as a variable name.
You can use either double quotes (") or single quotes (') for text/strings. As we saw before we can also save text in variables.
Let's use strings with variables!
End of explanation
your_string = 'something'
your_string
Explanation: Strings in Python are a bit more complicated because the operations on them aren't just + and * (though those are valid operations).
Dot notation and object oriented programming
Python, like many programming languages, supports Object Oriented Programming or OOP for short. In this paradigm, we approach ideas as Objects much as we do in the real world. Each Object is an instance of a Class or a type of object. Such an object may have certain properties or function that can be applied to them. 
So what does all this have to do with dot notation? Dot notation allows us to tell a instance of a class to use one of the functions inside that class. That is why we access the sqrt function from the math module with the dot. And why we access the 'upper' function of a string as my_string.upper()
<span style="color:red">Assignment (2 min):</span> Below, after your_string, type a dot and press Tab. You will get a list of function you can apply to the string. Pick two commands that seem interesting to you. 
Note that you have to define a string first to be able to get help. So first execute the cell so that the variable your_string is known. Then using the Tab key find one of your choice. 
Note: Don't worry about the ones that are difficult to understand. This is just to get you comfortable with the dot notation and finding functions and properties of objects.
End of explanation
items = [1, 3, 0, 4, 1]
Explanation: Lists
A list contains a sequence of items. You can concisely instruct Python to perform repeated actions on the elements of a list. Let's first create a list of numbers:
End of explanation
len(items)
Explanation: Note the syntax we used to create the list: square brackets [], and commas , to separate the items.
The built-in function len() returns the number of elements in a list:
End of explanation
sum(items)
Explanation: Now, let's compute the sum of all elements in the list. Python provides a built-in function for this:
End of explanation
items[0]
items[-1] 
Explanation: We can also access individual elements in the list, using the following syntax:
End of explanation
items[1] = 9
items
Explanation: Note that indexing starts at 0 in Python: the first element of the list is indexed by 0, the second by 1, and so on. Also, -1 refers to the last element, -2, to the penultimate element, and so on.
The same syntax can be used to alter elements in the list:
End of explanation
items[1:3]
Explanation: We can access sublists with the following syntax:
End of explanation
my_dict = {'a': 1, 'b': 2, 'c': 3}
print('a:', my_dict['a'])
list(my_dict.keys())
Explanation: Here, 1:3 represents a slice going from element 1 included (this is the second element of the list) to element 3 excluded. Thus, we get a sublist with the second and third element of the original list. The first-included/last-excluded asymmetry leads to an intuitive treatment of overlaps between consecutive slices. Also, note that a sublist refers to a dynamic view of the original list, not a copy; changing elements in the sublist automatically changes them in the original list.
<span style="color:red">Assignment (5 min):</span> In the code cell below make a list of the first 10 prime numbers: https://en.wikipedia.org/wiki/Prime_number. Use the sum() function to figure out the sum of the first 10 prime numbers. 
<span style="color:red">Assignment (1 min):</span>
Print the second-to-last prime number from your list to the screen. 
Dictionaries
Dictionaries contain key-value pairs. They are extremely useful and common. They allow you to map, or point, keys to values. In the example below the letters a,b,c are now pointing to the numbers 1,2,3. 
For a flux balance analysis application of a dictionary, you can think of a dictionary that points each of the reactions in a network to its flux in the FBA solution. 
You can access the value a certain key points to with square bracket notation:
End of explanation
my_dict = {18: 1, 23: 2, 0: 3}
my_dict[18]
Explanation: The keys in a dictionary can be anything including numbers
End of explanation
a_list = [1,2,3,4,5,6]
for number in a_list:
    number
Explanation: <span style="color:red">Assignment (1 min):</span> Make your own dictionary. For each person in your group add a 'key' to the dictionary, the name of the person, and a value, the age of the person. Then print the dictionary to the screen.
for loops
We can run through all elements of a list using a for loop:
End of explanation
genome_sizes = {'e. coli':5,'yeast':12,'human':2.9e3} # dictionary
print('A list of genome-sizes in #Mbp:')
for organism in genome_sizes.keys():
    print(organism,genome_sizes[organism])
Explanation: Note that the for loop steps in sequence through the numbers in the list. 
Every loop, the variable number is assigned the value of the next number in the list
You may call this variable number whatever you wish. As long as you also change it in the third line
As a more complex example, we can also loop over the keys of a dictionary.
End of explanation
items = [1,2,3,4,5,6]
squares = [item * item for item in items]
squares
Explanation: There are several things to note here:
The for organism in genome_sizes.keys() syntax means that a temporary variable named organism is created at every iteration. This variable contains the value of every item in the list, one at a time.
Note the colon : at the end of the for statement. Forgetting it will lead to a syntax error!
The  print statement will be executed for all items in the list.
Note the four spaces before print: this is called the indentation. You will find more details about indentation in the next subsection.
<span style="color:red">Assignment (3 min):</span> Write your own for loop that prints each element of your list of 10 prime numbers divided by 2 separately to the screen. 
list comprehensions
Python supports a concise syntax to perform a given operation on all elements of a list using for loops:
End of explanation
even = [item for item in items if item % 2 == 0]
even
Explanation: This is called a list comprehension. A new list is created here; it contains the squares of all numbers in the list. This concise syntax leads to highly readable and Pythonic code.
<span style="color:red">Assignment (3 min):</span> Write a list comprehension that calculates the magick square of each of the first 10 prime numbers. Start from the example above but loop over the list of prime numbers you defined above.
Python supports a concise syntax to select all elements in a list that satisfy certain properties. Here is how to create a sublist with only even numbers:
End of explanation
<END_TASK>