<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Programming for Network Research
Erick Peirson, PhD | erick.peirson@asu.edu | @captbarberousse
Last updated 20 January, 2016
0. Introduction.
1. First steps with Python.
2. Objects and types.
3. Flow control
Step1:  3. Flow control
Step2:  if says, "if the following statement is True*, then do the following...". Don't foget the colon (
Step3:  If I were to win the Powerball AND my friend could come to the LAN party, it would be a pretty great day. I can check for both of those things in one statement, using the and operator.
Step4:  Right, pretty unlucky. But I could get over my disappointment if I saw a puppy. So I'll throw in an or operator.
Step5:  Notice that I threw in some parentheses to group my evaluations. In the example above, the statement 
python
if (myfriend in invitees and x &lt; 1./292000000) or is_there_a_puppy
Step6:  You can use as many elifs as you like!
Step7:  3.3. Doing things over and over and over.
Sure, my chances of winning the powerball are pretty low for any given draw. The real trick is to play all the time! SOMEONE has to win, right?
This kind of repetitive task calls for a loop. A loop is a control structure in which we do some series of operations repeatedly until some condition is met.
For example, suppose that I have saved up for years and years and now have around $100,000 that I want to gamble away--- er, invest, in the Powerball.
Step8:  The statement...
python
while ...
Step9:  Now I need to turn those interaction counts into interaction rates, expressed in interactions per minute. I can iterate over the list of interaction counts, perform my math, and store the result in a new list. Notice
Step10:  This is called a for loop (bet you didn't see that coming). Unlike a while loop, which relies on a logical evaluation of some kind, for loops require something to iterate over. We call the thing that we're iterating over the iterator. A list is an iterator
Step11:  Strings are also iterators! I can get one character at a time
Step12:  Frequently you will need to perform a task some specific number of times, but not necessarily because you have an iterator of a particular size. For example, suppose I want to calculate $6!$. I know that I will need to perform four multiplication steps ($65432$). I can use the function xrange to create an iterator over a specified range of integers. For example
<ASSISTANT_TASK:>
Python Code:
import random    # Ignore me for now!
Explanation: Programming for Network Research
Erick Peirson, PhD | erick.peirson@asu.edu | @captbarberousse
Last updated 20 January, 2016
0. Introduction.
1. First steps with Python.
2. Objects and types.
3. Flow control: if, elif, else, and friends.
4. First steps with NetworkX.
5: I/O: working with data! Numpy and Pandas.
6: Our first tabular graph. Layout and visualization in Cytoscape.
7: Intro to NetworkX. GraphML. Advanced visualization in Cytoscape.
8: Blockmodels in NetworkX.
9: Properties of graphs: whole-graph statistics in NetworkX and Cytoscape.
10: Properties of nodes: centrality statistics.
11: ...
End of explanation
x = random.random() # This generates a random float between 0. and 1.
if x < 1./292000000:    # That there's some pretty low odss.
    print 'I won the powerball!'
else:
    print ':-('
Explanation: 3. Flow control: if, elif, else, and friends.
In most real-life programming situations, you'll need to do more than a linear set of procedures. Your programs will need to be able to make decisions based on a range of possible conditions. In this notebook we'll talk about how to perform logical operations.
3.1. if and else
The simplest form of decision-making in Python is dichotomous: if some condition is true, then do something; otherwise, do something else. If the weather is nice, then I'll wear sandals; otherwise, I'll wear shoes. If Moe and Curly win the election, I'll move to Norway; otherwise, I'll stay in New York. Notice the pattern: if...then...otherwise. In Python, we can write those kind of instructions almost as I've written the sentences above, using the statements if and else.
End of explanation
invitees = ['Jack', 'Jane', 'Jim', 'Jill', 'Joseph', 'Jay', 'Josephus']
myfriend = 'Greg'
if myfriend in invitees:
    print 'w00t!'
else:
    print 'l4me'
Explanation: if says, "if the following statement is True*, then do the following...". Don't foget the colon (:) afterwards, too. The part after the if statement, print 'I won...., is indented, so that Python knows which part should be conditionally executed. 
else says, "otherwise, do this...". Don't forget the colon! else is at the same level of indentation as the if statement, so that Python knows they go together. The part afterward, print ':-(', is indented, so that Python knows it's the part of the code that will get run in the "otherwise" case.
* In Python, the statement need only by "truthy" to be considered True. That is, it could be True, not 0 (or 0.0), or not an empty string.
There are all kinds of comparative operators. For a complete list, see this page. 
Here's an example of how to check whether or not a particular item is contained within a list. Say, for example, that I have a list of invitees for a super-secret-underground LAN party, and I want to know if my friend is on the list.
End of explanation
x = random.random()    # Come on, lucky numbers!
if myfriend in invitees and x < 1./292000000:
    print 'Best day ever!'
else:
    print 'meh.'
Explanation: If I were to win the Powerball AND my friend could come to the LAN party, it would be a pretty great day. I can check for both of those things in one statement, using the and operator.
End of explanation
x = random.random()    # I gamble for the thrill.
is_there_a_puppy = True
if (myfriend in invitees and x < 1./292000000) or is_there_a_puppy:
    print "This was much more likely, and I've adjusted my expectations."
else:
    print ':-|'
Explanation: Right, pretty unlucky. But I could get over my disappointment if I saw a puppy. So I'll throw in an or operator.
End of explanation
weather = 'blizzard'
footwear = None    # I know that I'm wearing something, but I'm not sure what yet.
if weather == 'sunny':      # ``==`` means "equal to".
    footwear = 'sandals'    # ``=`` means "assign the expression on the right to the variable on the left."
elif weather == 'blizzard':
    footwear = 'snow boots'
else:
    footwear = 'shoes'
    
print footwear
Explanation: Notice that I threw in some parentheses to group my evaluations. In the example above, the statement 
python
if (myfriend in invitees and x &lt; 1./292000000) or is_there_a_puppy:
evaluates as 
python
if (False and False) or True:
which gets further simplified to
python
if False or True:
which is just
python
if True:
3.2. elif
Quite often I want to make a decision that has more than two potential outcomes. Sure, if it's sunny outside I'm down for sandals, otherwise I'd rather wear shoes. But if it's a blizzard, I'm going for snow boots. Consider the elif operator (short for "else if"):
End of explanation
weather = 'cows'
footwear = None
if weather == 'sunny':
    footwear = 'sandals'
elif weather == 'blizzard':
    footwear = 'snow boots'
elif weather == 'rain':
    footwear = 'galoshes'
elif weather == 'cows':
    footwear = 'run away!'
else:
    footwear = 'shoes'
    
print footwear
Explanation: You can use as many elifs as you like!
End of explanation
my_life_savings = 100000
while my_life_savings > 0:    # While I still have money in the bank,
    my_life_savings -= 1      # ``-=`` means "subtract one and store the result in the same variable."
                              #  This is the same as writing: my_life_savings = my_life_savings - 1
    
    x = random.random()       # Wooo!
    if x < 1./292000000:
        print 'JACKPOT!!'
        break
Explanation: 3.3. Doing things over and over and over.
Sure, my chances of winning the powerball are pretty low for any given draw. The real trick is to play all the time! SOMEONE has to win, right?
This kind of repetitive task calls for a loop. A loop is a control structure in which we do some series of operations repeatedly until some condition is met.
For example, suppose that I have saved up for years and years and now have around $100,000 that I want to gamble away--- er, invest, in the Powerball.
End of explanation
interactions = [40,  44,  5,  26,  4,  47,  41,  41,  29,  5,  49,  32,    # You can write a list over multiple lines, 
                31,  6,  13,  13,  38,  42,  35,  34,  49,  43,  23,  21]  # just be sure to end the line with a comma.
Explanation: The statement...
python
while ...:
says: "as long as the following statement (...) is True, do the following thing over and over and over. Unsurprisingly, this is called a "while" loop. In the example above, we decrement (subtract 1) from our life savings every iteration, and stop when there is no money left (my_life_savings &lt;= 0).
Now, in the extremely unlikely case that I win the Powerball, there's really no incentive to keep playing. In that case, I want to stop the loop prematurely. To do that, I use the command break. break will stop the iteration at that very moment.
WARNING WARNING WARNING: avoid endless loops! If you use a while loop, make sure that the condition for the loop (the part that gets evaluated each iteration) will become False in some reasonable duration of time. Consider what would happen if I removed the line that decremented my life savings (my_life_savings -= 1): we'd go on playing the powerball forever! If you do start an endless loop by accident, use the square "stop" button (or select Kernel > Interrupt) in the menu at the top of the notebook.
Here's another case: suppose I have a bunch of measurements about how often individual ants in a colony of Pogonomyrmex barbatus interact with each other. 
I sat there with my little notebook for twenty minutes, and counted the number of times each pair of ants touched antennae. Now I have a list of interaction counts, one entry per pair of ants. It's a small colony, only 4 ants, so there are only $4! = 24$ entries.
End of explanation
interaction_frequencies = []    # Make a new, empty list.
for count in interactions:      # Each iteration, I get the next item, and I refer to it as ``count``.
    frequency = float(count)/20.    # Interactions per minute.
    interaction_frequencies.append(frequency)    # ``append()`` adds the value to the end of the list.
    
print interaction_frequencies
Explanation: Now I need to turn those interaction counts into interaction rates, expressed in interactions per minute. I can iterate over the list of interaction counts, perform my math, and store the result in a new list. Notice: my counts are ints, so in order to get a precise result during division I'll need to coerce them into floats.
End of explanation
for number in [0, 1, 2, 3, 4, 5]:
    print number
Explanation: This is called a for loop (bet you didn't see that coming). Unlike a while loop, which relies on a logical evaluation of some kind, for loops require something to iterate over. We call the thing that we're iterating over the iterator. A list is an iterator: it contains a bunch of elements, and I can get them one at a time.
End of explanation
for character in 'this string':
    print character
Explanation: Strings are also iterators! I can get one character at a time:
End of explanation
factorial = 6
for i in xrange(1, factorial - 1):    # Yields the ints 1, 2, 3, and 4.
    # ``*=`` means "Multiply this value by the value on the right, and store the result in the same variable.
    factorial *= factorial - i    # The same as: factorial = factorial * (factorial - i)
    
print factorial
Explanation: Frequently you will need to perform a task some specific number of times, but not necessarily because you have an iterator of a particular size. For example, suppose I want to calculate $6!$. I know that I will need to perform four multiplication steps ($65432$). I can use the function xrange to create an iterator over a specified range of integers. For example:
End of explanation
<END_TASK>