<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Table of Contents
<p><div class="lev1 toc-item"><a href="#Control-Flow" data-toc-modified-id="Control-Flow-1"><span class="toc-item-num">1&nbsp;&nbsp;</span>Control Flow</a></div><div class="lev2 toc-item"><a href="#Multiple-Conditions" data-toc-modified-id="Multiple-Conditions-11"><span class="toc-item-num">1.1&nbsp;&nbsp;</span>Multiple Conditions</a></div><div class="lev2 toc-item"><a href="#Exercise" data-toc-modified-id="Exercise-12"><span class="toc-item-num">1.2&nbsp;&nbsp;</span>Exercise</a></div><div class="lev2 toc-item"><a href="#Adding-your-own-input" data-toc-modified-id="Adding-your-own-input-13"><span class="toc-item-num">1.3&nbsp;&nbsp;</span>Adding your own input</a></div><div class="lev1 toc-item"><a href="#Loops" data-toc-modified-id="Loops-2"><span class="toc-item-num">2&nbsp;&nbsp;</span>Loops</a></div><div class="lev2 toc-item"><a href="#Exercise" data-toc-modified-id="Exercise-21"><span class="toc-item-num">2.1&nbsp;&nbsp;</span>Exercise</a></div><div class="lev1 toc-item"><a href="#Range-of-Values" data-toc-modified-id="Range-of-Values-3"><span class="toc-item-num">3&nbsp;&nbsp;</span>Range of Values</a></div><div class="lev2 toc-item"><a href="#Exercise" data-toc-modified-id="Exercise-31"><span class="toc-item-num">3.1&nbsp;&nbsp;</span>Exercise</a></div><div class="lev2 toc-item"><a href="#Exercise" data-toc-modified-id="Exercise-32"><span class="toc-item-num">3.2&nbsp;&nbsp;</span>Exercise</a></div><div class="lev1 toc-item"><a href="#Become-a-Control-Freak" data-toc-modified-id="Become-a-Control-Freak-4"><span class="toc-item-num">4&nbsp;&nbsp;</span>Become a Control Freak</a></div><div class="lev2 toc-item"><a href="#Break" data-toc-modified-id="Break-41"><span class="toc-item-num">4.1&nbsp;&nbsp;</span>Break</a></div><div class="lev2 toc-item"><a href="#Continue" data-toc-modified-id="Continue-42"><span class="toc-item-num">4.2&nbsp;&nbsp;</span>Continue</a></div><div class="lev1 toc-item"><a href="#List-Comprehension" data-toc-modified-id="List-Comprehension-5"><span class="toc-item-num">5&nbsp;&nbsp;</span>List Comprehension</a></div><div class="lev2 toc-item"><a href="#Dictionary-Comprehension" data-toc-modified-id="Dictionary-Comprehension-51"><span class="toc-item-num">5.1&nbsp;&nbsp;</span>Dictionary Comprehension</a></div>
# Control Flow
Now that we have some basic skills, it's important for us to define the conditions in which they can be executed. This is where control comes into play. 
And as before, very easy topic!
In plain English
Step1:  Multiple Conditions
So now we can deal with a scenario where there are two possible decisions to be made. What about more than two decision?
Say hello to "elif"!
Step2:  Exercise
Write some code to check if you are old enough to buy a bottle of wine. You need to be 18 or over, but if your State is Texas, you need to be 25 or over.
Step3:  Adding your own input
How about adding your own input and checking against that? This doesn't come in too handy in a data science environment since you typically have a well defined dataset already. Nevertheless, this is important to know.
Step4:  Loops
Time to supercharge our Python usage. Loops are in some ways, the basis for automation. Check if a condition is true, then execute a step, and keep executing it till the condition is no longer true.
Step5:  When using dictionaries, you can iterate through keys, values or both.
Step6:  Exercise
Print the names of the people in the dictionary 'data'
Print the name of the people who have 'incubees'
Print the name, and net worth of people with a net worth higher than 500,000
Print the names of people without a board seat
Enter your responses in the fields below. This is solved for you if you scroll down, but you can't cheat yourself!
Step7:  Range of Values
We often need to define a range of values for our program to iterate over.
Step8:  In a defined range, the lower number is inclusive, and upper number is exclusive. So 0 to 10 would include 0 but exclude 10. So if we need a specific range, we can use this knowledge to our advantage.
Step9:  We can also specify a range without explicitly defining an upper or lower range, in which case, Python does it's magic
Step10:  We can also use the range function to perform mathematical tricks.
Step11:  Or to check for certain other conditions or properties, or to define how many times an activity will be performed.
Step12:  Exercise
Print all numbers from 1 to 20
Step13:  Exercise
Print the square of the first 10 natural numbers.
Step14:  Become a Control Freak
And now, it's time to become a master of control! A data scientist needs absolute control over loops, stopping when defined conditions are met, or carrying on till a solution if found.
<img src="images/break.jpg">
Break
Step15:  Continue
Break's cousin is called Continue.
If a certain condition is met, carry on.
Step16:  List Comprehension
Remember lists? Now here's a way to power through a large list in one line!
As a Data Scientist, you will need to write a lot of code very efficiently, especially in the data exploration stage. The more experiments you can run to understand your data, the better it is. This is also a very useful tool in transforming one list (or dictionary) into another list.
Let's begin by some simple examples
First, we will write a program to generate the squares of the first 10 natural numbers, using a standard for loop. 
Next, we will contrast that with the List Comprehension approach.
Step17:  So far, so good!
Step18:  How's that for speed?!
Here's the format for List Comprehensions, in English.
ListName = [Expected_Result_or_Operation for Item in a given range]<br>
print the ListName
Step19:  List comprehensions are very useful when dealing with an existing list. Let's see some examples.
Step20:  How about calculating the areas of circles, given a list of radii? That too in just one line.
Step21:  Dictionary Comprehension
Let's get back to our dictionary named Data. Dictionary Comprehension can be a very efficient way to extract information out of them. Especially when you have thousands or millions of records.
Step22:  We can also use dictionary comprehension to create new dictionaries
<ASSISTANT_TASK:>
Python Code:
collection = [1,2,3,4,5]
len(collection)
if len(collection) == 5:
    print("Woohoo!")
collection[1]
if collection[0] % 2 == 0:
    print("Divisible")
else:
    print("Not Divisible")
Explanation: Table of Contents
<p><div class="lev1 toc-item"><a href="#Control-Flow" data-toc-modified-id="Control-Flow-1"><span class="toc-item-num">1&nbsp;&nbsp;</span>Control Flow</a></div><div class="lev2 toc-item"><a href="#Multiple-Conditions" data-toc-modified-id="Multiple-Conditions-11"><span class="toc-item-num">1.1&nbsp;&nbsp;</span>Multiple Conditions</a></div><div class="lev2 toc-item"><a href="#Exercise" data-toc-modified-id="Exercise-12"><span class="toc-item-num">1.2&nbsp;&nbsp;</span>Exercise</a></div><div class="lev2 toc-item"><a href="#Adding-your-own-input" data-toc-modified-id="Adding-your-own-input-13"><span class="toc-item-num">1.3&nbsp;&nbsp;</span>Adding your own input</a></div><div class="lev1 toc-item"><a href="#Loops" data-toc-modified-id="Loops-2"><span class="toc-item-num">2&nbsp;&nbsp;</span>Loops</a></div><div class="lev2 toc-item"><a href="#Exercise" data-toc-modified-id="Exercise-21"><span class="toc-item-num">2.1&nbsp;&nbsp;</span>Exercise</a></div><div class="lev1 toc-item"><a href="#Range-of-Values" data-toc-modified-id="Range-of-Values-3"><span class="toc-item-num">3&nbsp;&nbsp;</span>Range of Values</a></div><div class="lev2 toc-item"><a href="#Exercise" data-toc-modified-id="Exercise-31"><span class="toc-item-num">3.1&nbsp;&nbsp;</span>Exercise</a></div><div class="lev2 toc-item"><a href="#Exercise" data-toc-modified-id="Exercise-32"><span class="toc-item-num">3.2&nbsp;&nbsp;</span>Exercise</a></div><div class="lev1 toc-item"><a href="#Become-a-Control-Freak" data-toc-modified-id="Become-a-Control-Freak-4"><span class="toc-item-num">4&nbsp;&nbsp;</span>Become a Control Freak</a></div><div class="lev2 toc-item"><a href="#Break" data-toc-modified-id="Break-41"><span class="toc-item-num">4.1&nbsp;&nbsp;</span>Break</a></div><div class="lev2 toc-item"><a href="#Continue" data-toc-modified-id="Continue-42"><span class="toc-item-num">4.2&nbsp;&nbsp;</span>Continue</a></div><div class="lev1 toc-item"><a href="#List-Comprehension" data-toc-modified-id="List-Comprehension-5"><span class="toc-item-num">5&nbsp;&nbsp;</span>List Comprehension</a></div><div class="lev2 toc-item"><a href="#Dictionary-Comprehension" data-toc-modified-id="Dictionary-Comprehension-51"><span class="toc-item-num">5.1&nbsp;&nbsp;</span>Dictionary Comprehension</a></div>
# Control Flow
Now that we have some basic skills, it's important for us to define the conditions in which they can be executed. This is where control comes into play. 
And as before, very easy topic!
In plain English:
* If condition x is True:
    * Execute statement A
* Else:
    * Execute statement B
And that's all there is to it. Now we just need to learn the Python-way of expressing the above phrases.
End of explanation
collection = [1,2,3,4,5]
if collection[0] == 0:
    print ("Zero!")
elif collection[0] == 100:
    print ("Hundred!")
else:
    print("Not Zero or Hundred")
x = ["George", "Barack", "Donald"]
test = "Richard"
if test in x:
    print(test, "has been found.")
else:
    print(test, "was not found. Let me add him to the list." )
    x.append(test)
print(x)
Explanation: Multiple Conditions
So now we can deal with a scenario where there are two possible decisions to be made. What about more than two decision?
Say hello to "elif"!
End of explanation
# Your code here
Explanation: Exercise
Write some code to check if you are old enough to buy a bottle of wine. You need to be 18 or over, but if your State is Texas, you need to be 25 or over.
End of explanation
age = int(input("Please enter your age:"))
if age < 18:
    print("You cannot vote or buy alcohol.")
elif age < 21:
    print("You can vote, but can't buy alcohol.")
else:
    print("You can vote to buy alcohol. ;) ")
mr_prez = ["Bill", "George", "Barack", "Donald"]
name = input("Enter your name:") # Don't need to specify str
type(name)
if name in mr_prez:
    print("You share your name with a President.")
else:
    print("You too can be president some day.")
Explanation: Adding your own input
How about adding your own input and checking against that? This doesn't come in too handy in a data science environment since you typically have a well defined dataset already. Nevertheless, this is important to know.
End of explanation
numbers = [1,2,3,4,5,6,7,8,9,10]
for number in numbers:
    if number % 2 == 0:
        print("Divisible by 2.")
    else:
        print("Not divisible by 2.")
numbers = {1,2,3,4,5,6,7,8,9,10}
for num in numbers:
    if num%3 == 0:
        print("Divisible by 3.")
    else:
        print("Not divisible by 3.")
Explanation: Loops
Time to supercharge our Python usage. Loops are in some ways, the basis for automation. Check if a condition is true, then execute a step, and keep executing it till the condition is no longer true.
End of explanation
groceries = {"Milk":2.5, "Tea": 4, "Biscuits": 3.5, "Sugar":1}
print(groceries.keys())
print(groceries.values())
# item here refers to the the key in set name groceries
for a in groceries.keys():
    print(a)
for price in groceries.values():
    print(price)
for (key, val) in groceries.items():
    print(key,val)
groceries.items()
groceries.keys()
groceries.values()
Explanation: When using dictionaries, you can iterate through keys, values or both.
End of explanation
data = {
        "Richard": {
            "Title": "CEO", 
            "Employees": ["Dinesh", "Gilfoyle", "Jared"],
            "Awards": ["Techcrunch Disrupt"],
            "Previous Firm": "Hooli",
            "Board Seat":1,
            "Net Worth": 100000
        }, 
        "Jared": {
            "Real_Name": "Donald", 
            "Title": "CFO",
            "Previous Firm": "Hooli",
            "Board Seat":1,
            "Net Worth": 500
        },
        "Erlich": { 
            "Title": "Visionary", 
            "Previous Firm": "Aviato", 
            "Current Firm": "Bachmannity",
            "Incubees": ["Richard", "Dinesh", "Gilfoyle", "Nelson", "Jian Yang"],
            "Board Seat": 1,
            "Net Worth": 5000000
        }, 
        "Nelson": { 
            "Title": "Co-Founder", 
            "Current Firm": "Bachmannity", 
            "Previous Firm": "Hooli",
            "Board Seat": 0,
            "Net Worth": 10000000
        },
    }
# Name of people in the dictionary
data.keys()
# Alternate way to get the name of the people in the dictionary
for name in data.keys():
    print(name)
# Name of people who have incubees
for name in data.items():
    if "Incubees" in name[1]:
        print (name[0])
# Name and networth of people with a networth greater 500000
for name in data.items():
    if "Net Worth" in name[1] and name[1]["Net Worth"]>500000:
        print (name[0], name[1]["Net Worth"])
# Name of people who don't have a board seat
for name in data.items():
    if "Board Seat" in name[1] and name[1]["Board Seat"]  == 0:
        print (name[0])
Explanation: Exercise
Print the names of the people in the dictionary 'data'
Print the name of the people who have 'incubees'
Print the name, and net worth of people with a net worth higher than 500,000
Print the names of people without a board seat
Enter your responses in the fields below. This is solved for you if you scroll down, but you can't cheat yourself!
End of explanation
# Generate a list on the fly
nums = list(range(10))
print(nums)
Explanation: Range of Values
We often need to define a range of values for our program to iterate over.
End of explanation
nums = list(range(1,11))
print(nums)
Explanation: In a defined range, the lower number is inclusive, and upper number is exclusive. So 0 to 10 would include 0 but exclude 10. So if we need a specific range, we can use this knowledge to our advantage.
End of explanation
nums = list(range(10))
print(nums)
Explanation: We can also specify a range without explicitly defining an upper or lower range, in which case, Python does it's magic: range will be 0 to one less than the number specified.
End of explanation
for i in range(1,6):
    print("The square of",i,"is:",i**2)
Explanation: We can also use the range function to perform mathematical tricks.
End of explanation
for i in range(1,10):
    print("*"*i)
Explanation: Or to check for certain other conditions or properties, or to define how many times an activity will be performed.
End of explanation
# Your Code Here
Explanation: Exercise
Print all numbers from 1 to 20
End of explanation
# Your Code Here
Explanation: Exercise
Print the square of the first 10 natural numbers.
End of explanation
for i in range(1,100):
    print("The square of",i,"is:",i**2)
    if i >= 5:
        break
print("Broken")
Explanation: Become a Control Freak
And now, it's time to become a master of control! A data scientist needs absolute control over loops, stopping when defined conditions are met, or carrying on till a solution if found.
<img src="images/break.jpg">
Break
End of explanation
letters = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]
for letter in letters:
    print("Currently testing letter", letter)
    if letter == "e":
        print("I plead the 5th!")
        continue
    print( letter)
Explanation: Continue
Break's cousin is called Continue.
If a certain condition is met, carry on.
End of explanation
# Here is a standard for loop
numList = []
for num in range(1,11):
    numList.append(num**2)
print (numList)
Explanation: List Comprehension
Remember lists? Now here's a way to power through a large list in one line!
As a Data Scientist, you will need to write a lot of code very efficiently, especially in the data exploration stage. The more experiments you can run to understand your data, the better it is. This is also a very useful tool in transforming one list (or dictionary) into another list.
Let's begin by some simple examples
First, we will write a program to generate the squares of the first 10 natural numbers, using a standard for loop. 
Next, we will contrast that with the List Comprehension approach.
End of explanation
# Now for List Comprehension
sqList = [num**2 for num in range(1,11)]
print(sqList)
[num**2 for num in range(1,11)]
Explanation: So far, so good!
End of explanation
cubeList = [num**3 for num in range(6)]
print(cubeList)
Explanation: How's that for speed?!
Here's the format for List Comprehensions, in English.
ListName = [Expected_Result_or_Operation for Item in a given range]<br>
print the ListName
End of explanation
nums = [1,2,3,4,5,6,7,8,9,10]
# For every n in the list named nums, I want an n
my_list1 = [n for n in nums]
print(my_list1)
# For every n in the list named nums, I want n to be squared
my_list2 = [n**2 for n in nums]
print(my_list2)
# For every n in the list named nums, I want n, only if it is even
my_list3 = [n for n in nums if n%2 == 0]
print(my_list3)
Explanation: List comprehensions are very useful when dealing with an existing list. Let's see some examples.
End of explanation
radius = [1.0, 2.0, 3.0, 4.0, 5.0]
import math
# Area of Circle = Pi * (radius**2)
area = [round((r**2)*math.pi,2) for r in radius]
print(area)
Explanation: How about calculating the areas of circles, given a list of radii? That too in just one line.
End of explanation
data = {
        "Richard": {
            "Title": "CEO", 
            "Employees": ["Dinesh", "Gilfoyle", "Jared"],
            "Awards": ["Techcrunch Disrupt"],
            "Previous Firm": "Hooli",
            "Board Seat":1,
            "Net Worth": 100000
        }, 
        "Jared": {
            "Real_Name": "Donald", 
            "Title": "CFO",
            "Previous Firm": "Hooli",
            "Board Seat":1,
            "Net Worth": 500
        },
        "Erlich": { 
            "Title": "Visionary", 
            "Previous Firm": "Aviato", 
            "Current Firm": "Bachmannity",
            "Incubees": ["Richard", "Dinesh", "Gilfoyle", "Nelson", "Jian Yang"],
            "Board Seat": 1,
            "Net Worth": 5000000
        }, 
        "Nelson": { 
            "Title": "Co-Founder", 
            "Current Firm": "Bachmannity", 
            "Previous Firm": "Hooli",
            "Board Seat": 0,
            "Net Worth": 10000000
        },
    }
# Print all details for people who have incubees
[(k,v) for k, v in data.items() if "Incubees" in v ]
for name in data.items():
    if "Net Worth" in name[1] and name[1]["Net Worth"]>500000:
        print (name[0], name[1]["Net Worth"])
high_nw = [(name[0], name[1]["Net Worth"]) for name in data.items() if "Net Worth" in name[1] and name[1]["Net Worth"]>500000]
print(high_nw)
type(high_nw)
type(high_nw[0])
Explanation: Dictionary Comprehension
Let's get back to our dictionary named Data. Dictionary Comprehension can be a very efficient way to extract information out of them. Especially when you have thousands or millions of records.
End of explanation
name = ['George HW', 'Bill', 'George', 'Barack', 'Donald', 'Bugs']
surname = ['Bush', 'Clinton', 'Bush Jr', 'Obama', 'Trump', 'Bunny']
full_names = {n:s for n,s in zip(name,surname)}
full_names
# What if we want to exclude certain values?
full_names = {n:s for n,s in zip(name, surname) if n!='Bugs'}
print(full_names)
Explanation: We can also use dictionary comprehension to create new dictionaries
End of explanation
<END_TASK>