In [1]:
print("Hello World 2!")


Hello World 2!

Code Description

This is a hello world program for Python.


In [4]:
for i in range(20):
    if i<10:
        print("%d - less than 10" %(i))
    elif i==10:
        print("%d - exactly 10" %(i))
    else:
        print ("%d - greater than 10" %(i))


0 - less than 10
1 - less than 10
2 - less than 10
3 - less than 10
4 - less than 10
5 - less than 10
6 - less than 10
7 - less than 10
8 - less than 10
9 - less than 10
10 - exactly 10
11 - greater than 10
12 - greater than 10
13 - greater than 10
14 - greater than 10
15 - greater than 10
16 - greater than 10
17 - greater than 10
18 - greater than 10
19 - greater than 10

In [6]:
def hello(name="NYU student"):
        print("Hello %s" %(name))

hello()
hello("Anurag")


Hello NYU student
Hello Anurag

In [10]:
animals = []
animals.append("bear")
animals.append("lion")
animals.append("monkey")
animals.append("unicorn")
print(animals)


['bear', 'lion', 'monkey', 'unicorn']

In [14]:
print(animals[0])
for animal in animals:
    print(animal)


bear
bear
lion
monkey
unicorn

In [15]:
a=animals.pop()
print(a)
print(animals)


unicorn
['bear', 'lion', 'monkey']

In [17]:
animals.append("bear")
animals.sort()
print(animals)


['bear', 'bear', 'lion', 'monkey']

In [20]:
animals.append("unicorn")
newlist = [a for a in animals if a!="bear"]
print(newlist)


['lion', 'monkey', 'unicorn', 'unicorn']

In [25]:
import random
random.randint(0,10)


Out[25]:
4

In [26]:
import numpy as np
np.power(2,2)


Out[26]:
4

In [27]:
from random import *
randint(0,10)


Out[27]:
9

In [28]:
import numpy as np
import matplotlib.pyplot as plt
X = np.linspace(-np.pi,np.pi,256,endpoint=True)
C,S = np.cos(X), np.sin(X)

plt.plot(X,C)
plt.plot(X,S)

plt.show()



In [ ]: