In [3]:
x=500
y=5.0
z="Hello"
print x,y
print type(x)
print type(y)
print type(z)
In [9]:
#print "Hello, world!" as many times as you want
for i in range(0,5,1):
print "Hi"
In [64]:
print " First ==========="
for i in range(2):
print i
for j in range(1):
print j
print " second ==========="
for i in range(3):
for j in range(1):
print i
print j
In [126]:
for i in range(1,11,1):
for j in range(1,11,1):
print i*j
# How can we print out in one line?
# How many lines after for will be affected by the for command and how can we separate them?
In [125]:
x=5
y=7
if x>y :
print "x is greater than y"
elif x<y:
print "x is smaller than y"
else:
print "x and y are equal"
In [55]:
# How can we couple two loops? It starts with i=0 and then does not go to loop j in the First case .
# while for the case 2 it is true. So when you fill the gap between two loops you automacillay separete two loops and
# they will work separeately.
In [74]:
def sum(x,y):
sum=x+y
return sum
Z=sum(5,7)
print Z
In [84]:
import numpy
a=numpy.array([11,23,43,54])
print a
print a[0],a[3]
print a[1:3]
print a[2:]
# the lower index in a slicing range is inclusive, while the upper index is exclusive
In [95]:
if x>=7 and x<=10 :
print "x is between 7 and 10"
elif x>10 or x<7 :
print " x is out of data"
In [100]:
p=True
if(p):
x=5
else:
x=7
print x
In [150]:
import numpy #can't forget this!
import matplotlib.pyplot as plt #our shortcut
x = numpy.linspace(-4,4,30) #create our first array
y1 = x**2 #this is how Python does exponents
y2 = x**3
plt.plot(x,y1)and plt.plot(x,y3) #create the plot
plt.show() #show the plot
# linspace means from 0 to 5 devided by 20 sections.
In [102]:
a=numpy.array([1,2,3])
b=a.copy()
print b
b[1]=7
print a
print b
# in this case any changing in b does not lead to change in a (just b). however if we assugned b=a instead of
# b.a.copy() by changing the b also array a changes.
In [146]:
# How can we edit our graph or creating contour?
In [ ]: