## 3: The math module

### Instructions

Use the sqrt() function within the math module to assign the square root of 16.0 to a.

Use the ceil() function within the math module to assign the ceiling of 111.3 to b.

Use the floor() function within the math module to assign the floor of 89.9 to c.

``````

In [1]:

import math

``````

``````

In [2]:

a = math.sqrt(16.0)
b = math.ceil(111.3)
c = math.floor(89.9)

``````
``````

In [3]:

print(a, b, c)

``````
``````

4.0 112 89

``````

## 4: Variables within modules

### Instructions

Assign the square root of pi to a.

Assign the ceiling of pi to b.

Assign the floor of pi to c.

``````

In [4]:

import math

print(math.pi)

``````
``````

3.141592653589793

``````

``````

In [5]:

PI = math.pi
a = math.sqrt(PI)
b = math.ceil(PI)
c = math.floor(PI)

``````
``````

In [6]:

print(a, b, c)

``````
``````

1.7724538509055159 4 3

``````

## 5: The csv module

### Instructions

Read in all of the data from "nfl.csv" into a list variable named nfl using the csv module.

``````

In [9]:

import csv

f = open("nfl.csv")

``````
``````

In [10]:

print(nfl)

``````
``````

``````

## 6: Counting how many times a team won

### Instructions

Fill in the mission code to do the following:

Import and use the csv module to load data from our "nfl.csv" file.

Count how many games the "New England Patriots" won from 2009-2013. To do this, set a counter to 0, and increment by 1 whenever you see a row whose winner column is equal to "New England Patriots".

Assign the count to patriots_wins.

``````

In [12]:

import csv

f = open("nfl.csv")
patriots_wins = 0

for row in data:
if row[2] == "New England Patriots":
patriots_wins += 1
print(patriots_wins)

``````
``````

10

``````

## 7: Making a function to count wins

### Instructions

Write a function called nfl_wins that will take a team name as input.

The function should return the number of wins the team had from 2009-2013.

Use the function to assign the number of wins by the "Dallas Cowboys" to cowboys_wins.

Use the function to assign the number of wins by the "Atlanta Falcons" to falcons_wins.

``````

In [13]:

import csv

f = open("nfl.csv", 'r')

def nfl_wins(team):
team_wins = 0

for row in nfl:
if row[2] == team:
team_wins += 1

return team_wins

cowboys_wins = nfl_wins("Dallas Cowboys")
falcons_wins = nfl_wins("Atlanta Falcons")

print(cowboys_wins, falcons_wins)

``````
``````

10 7

``````

## 10: Counting wins in a given year

### Instructions

Modify the nfl_wins function so that it takes a team name, in the form of a string, and a year, also in the form of a string, as input. Call this new function nfl_wins_in_a_year

Your function should output the number of wins the team had in the given year, as an integer. Use the and operator to combine booleans, checking whether the desired team won and whether the game happened in the correct year for each row in the dataset.

Use your function to assign the number of wins by the "Cleveland Browns" in "2010" to browns_2010_wins.

Use your function to assign the number of wins by the "Philadelphia Eagles" in "2011" to eagles_2011_wins.

``````

In [14]:

import csv

f = open("nfl.csv", 'r')

def nfl_wins(team):
count = 0
for row in nfl:
if row[2] == team:
count = count + 1
return count

``````
``````

In [15]:

def nfl_wins_in_a_year(team, year):
count = 0
for row in nfl:
if row[0] == year and row[2] == team:
count = count + 1
return count

browns_2010_wins = nfl_wins_in_a_year("Cleveland Browns", "2010")

``````
``````

In [16]:

print(browns_2010_wins, eagles_2011_wins)

``````
``````

0 0

``````
``````

In [ ]:

``````