In [1]:
2 + 2
Out[1]:
In [2]:
(1 + 3) * 4
Out[2]:
In [3]:
cups_of_flour = 5
cups_of_flour * 0.5
Out[3]:
In [4]:
1/2
Out[4]:
In [5]:
1.0/2
Out[5]:
In [6]:
1/2.0
Out[6]:
In [7]:
"Hello" + 1
In [ ]:
"Hello" + str(1)
In [ ]:
"Hello" + `1`
In [ ]:
"hello" * 5
In [8]:
a = 1
a
Out[8]:
In [9]:
a = None
a
In [10]:
not None
Out[10]:
In [11]:
None != False
Out[11]:
In [12]:
if 2 > 1:
print "Hello World!"
In [13]:
if 1 > 2:
print "Hello World!"
else:
print "World is not a beautiful place!"
In [14]:
if 1 > 2:
print "Hello World!"
elif 2 > 3:
print "World is even better!"
elif 3 > 4:
print "I don't want to live here!"
else:
print "World is not a beautiful place!"
In [15]:
a = None
if a is None:
print "a is None"
else:
print "a is not None"
b = 10
if b == None:
print "b is None"
else:
print "b is not None"
In [16]:
list1 = [1, 2, 4, 2, 100]
s = "Hello world"
In [17]:
if 4 in list1:
print "Hey! 4 exists in list1"
In [18]:
if 2 in list1:
i = list1.index(2)
print "Search successful. Found at index {0}".format((i+1))
In [19]:
if 'o' in s:
print "'o' exists!"
In [20]:
if 'llo' in s:
print "'llo' exists!"
In [21]:
if 'house' not in s:
print "house not found!"
Create a list with at least 6 names inside it. Write an if/else test case to test the following
In [22]:
count = 0
while count < 10:
print count
count += 1 # count = count + 1
In [23]:
i = 0;
while i < 5:
j = 5;
while j > 0:
print i, j
j -= 1
i += 1
In [24]:
count = 0
while count < 10:
print count
count += 1 # count = count + 1
if count == 5:
break
In [25]:
count = 0
while count < 10:
count += 1 # count = count + 1
if count < 5:
continue
print count
In [26]:
count = 0
while count < 10:
print count
count += 1 # count = count + 1
if count < 5:
pass
else:
break