In [1]:
2+2
Out[1]:
4
In [2]:
3*5
Out[2]:
15
In [3]:
4-3
Out[3]:
1
In [4]:
9/4
Out[4]:
2.25
In [5]:
9//4
Out[5]:
2
In [6]:
2**8
Out[6]:
256
In [8]:
1
2
3+17
Out[8]:
20
In [9]:
print(60*'ha')
hahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahaha

Assignment

This is my report

Section 1

hello

In [10]:
a = 33
In [11]:
a
Out[11]:
33
In [12]:
a = 'hello'
In [13]:
a
Out[13]:
'hello'
In [14]:
a,b = 3,4
In [15]:
a
Out[15]:
3
In [16]:
b
Out[16]:
4
In [17]:
a = 16
b = 12
In [18]:
a = b
In [19]:
a
Out[19]:
12
In [20]:
b
Out[20]:
12
In [24]:
a, b = 12, 16
In [25]:
temp = a
a = b
b = temp
In [26]:
a,b
Out[26]:
(16, 12)
In [27]:
a, b = 12, 16
In [28]:
a,b = b,a
In [29]:
a,b
Out[29]:
(16, 12)
In [30]:
a
Out[30]:
16
In [31]:
a = a - 1
In [32]:
a
Out[32]:
15
In [33]:
a -= 1
In [34]:
a
Out[34]:
14
In [35]:
a -= 10
In [36]:
a
Out[36]:
4

"while" loop

In [37]:
i = 10
while i>0:
    i -= 1
    print(i)
print('Done!')
9
8
7
6
5
4
3
2
1
0
Done!
In [ ]:
while a != b:
    do something

while a==b:

In [ ]:
a = 647261945617
b = 793491798
write code to generate gcd of a,b
In [41]:
def gcd(a,b):
    #print('a+b=',a+b)
    return a+b
In [42]:
gcd(3,7)
Out[42]:
10

Conditional execution

In [43]:
a = 3
b = 17
if a<b:
    print('Wow!')
Wow!
In [44]:
a = 3000000
b = 17
if a<b:
    print('Wow!')
In [ ]:
def mygcd(a,b):
    while a!=b:
        if a<b:
            fix it
        replace a by a-b
        
    return a