Create a function that receives two inputs a and b, and returns the product of the a decimal of pi and the b decimal of pi.
i.e,
pi = 3.14159
if a = 2 and b = 4
result = 4 * 5
result = 20
Caveats:
In [ ]:
from math import pi
def mult_dec_pi(a, b):
# Add the solution here
result = ''
return result
In [ ]:
mult_dec_pi(a=2, b=4)
# 20.0
In [ ]:
mult_dec_pi(a=5, b=10)
# 45.0
In [ ]:
mult_dec_pi(a=14, b=1)
# 9.0
In [ ]:
mult_dec_pi(a=6, b=8)
# 10.0
In [ ]:
# Bonus
mult_dec_pi(a=16, b=4)
# 'Error'
In [1]:
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
# Import data
raw_data = """
Year,Employed,GNP
1947,60.323,234.289
1948,61.122,259.426
1949,60.171,258.054
1950,61.187,284.599
1951,63.221,328.975
1952,63.639,346.999
1953,64.989,365.385
1954,63.761,363.112
1955,66.019,397.469
1956,67.857,419.18
1957,68.169,442.769
1958,66.513,444.546
1959,68.655,482.704
1960,69.564,502.601
1961,69.331,518.173
1962,70.551,554.894"""
data = []
for line in raw_data.splitlines()[2:]:
words = line.split(',')
data.append(words)
data = np.array(data, dtype=np.float)
n_obs = data.shape[0]
plt.plot(data[:, 2], data[:, 1], 'bo')
plt.xlabel("GNP")
plt.ylabel("Employed")
Out[1]:
In [ ]: