In [23]:
%matplotlib inline
import matplotlib.pyplot as plt

My First Square Roots

This is my first notebook where I'm going to implement the Babylonian square root algorithm in Python


In [1]:
2*2


Out[1]:
4

In [2]:
9+3


Out[2]:
12

In [3]:
15-7


Out[3]:
8

In [4]:
34/9


Out[4]:
3.7777777777777777

In [5]:
4**5


Out[5]:
1024

In [6]:
variable = 6

In [7]:
variable


Out[7]:
6

In [8]:
variable * 3


Out[8]:
18

In [9]:
a = 1.5

In [10]:
1.5 ** 2


Out[10]:
2.25

In [11]:
1.25 ** 2


Out[11]:
1.5625

In [16]:
a= [1.5]

for i in range(10):
    next = a[i]+2
    a.append(next)

In [17]:
a


Out[17]:
[1.5, 3.5, 5.5, 7.5, 9.5, 11.5, 13.5, 15.5, 17.5, 19.5, 21.5]

In [18]:
a[0]


Out[18]:
1.5

In [19]:
a:[0:5]


  File "<ipython-input-19-48236528f928>", line 1
    a:[0:5]
        ^
SyntaxError: invalid syntax

In [24]:
a[0:5]


Out[24]:
[1.5, 3.5, 5.5, 7.5, 9.5]

In [28]:
plt.plot(a, 'o')
plt.title("My First Sequence")


Out[28]:
<matplotlib.text.Text at 0x10f32d400>

In [26]:
plt.plot?

In [35]:
b=[1.5]

for i in range (10):
    next = b[i]*2
    b.append(next)

In [38]:
plt.plot (b, '--o')
plt.plot (a, '--o')
plt.title("My Second Sequence")


Out[38]:
<matplotlib.text.Text at 0x10f7ad4a8>

In [36]:
b


Out[36]:
[1.5, 3.0, 6.0, 12.0, 24.0, 48.0, 96.0, 192.0, 384.0, 768.0, 1536.0]

In [ ]: