In [ ]:
print('Hello World')
In [ ]:
help(random)
Some useful to get help in Jupyter Notebook:
Shift
+ Tab
over a function inside a code cell.
In [ ]:
random.random?
The magics we are going to use the most: %%time, %%timeit, and %matplotlib. More info about magics here.
In [ ]:
%lsmagic
In [46]:
import math #imports the whole module. It requires to use the prefix "math." before calling each function
from math import * #imports all functions and variable within the current namespace (it does not require to use the prefix)
from math import cos, pi #imports only the specific functions and variables listed
Try using the different import options to describe the following expression:
x = cos(2 *pi)
In [ ]:
x = math.cos(2 * math.pi)
x = cos(2 * pi)
print(x)
In [ ]:
import random
In [ ]:
def sumTwoRandomNumbers():
a = random.random()
b = random.random()
c = a+b
print ('a: ', a, ' b: ', b)
print(type(a))
return c
In [ ]:
sumTwoRandomNumbers()
In [ ]:
def sumTwoGivenNumbers(a, b):
c = a+b
return c
In [ ]:
sumTwoGivenNumbers(23, 7)
In [ ]:
def sumMultipleNumbers(*args):
c = sum(args)
return c
In [ ]:
sumMultipleNumbers(1,2,3)
In [ ]:
def opMultipleNumbers(*args, **kwargs):
if kwargs.get("operation") == "sum":
c = sum(args)
if kwargs.get("operation") == "avg":
c = sum(args)/len(args)
return c
In [ ]:
opMultipleNumbers(1,2,3,4,operation="avg")
In [51]:
randomNumbers = [random.random() for i in range(1,10)]
s = sum(randomNumbers)
r = [ i/s for i in randomNumbers ]
print (r)
print(sum(r))
In [ ]: