In this notebook, you will guess the output of simple Python statements. You should be able to correctly predict most (if not all) of them. If you get something wrong, figure out why!
3 + 10
3 = 10
3 == 10
3 ** 10
'3 + 10'
3 * '10'
a*10
'a' * 10
int('3') + int('10')
int('hello world')
10 / 5
10 / 4
float(10 / 4)
float(10)/4
type("True")
type(True)
a=3
if (a==3):
print "it's a three!"
a=3
if a==3:
print "it's a four!"
a=3
if a=4:
print "it's a four!"
a=3
if a<10:
print "we're here"
elif a<100:
print "and also here"
a=3
if a<10:
print "we're here"
if a<100:
print "and also here"
a = "True"
if a:
print "we're in the 'if'"
else:
print "we're in the else"
a = "False"
if a:
print "we're in the 'if'"
else:
print "we're in the 'else'"
a = 5
b = 10
if a and b:
print "a is", a
print "b is", b
c = 20
if c or d:
print "c is", c
print "d is", d
c = 20
if c and d:
print "c is", c
print "d is", d
animals= ['dog', 'cat', 'panda']
if panda in animals:
print "a hit!"
animals= ['dog', 'cat', 'panda']
if "panda" or "giraffe" in animals:
print "a hit!"
if ["dog", "cat"] in animals:
print "we're here"
some_nums = range(1,10)
print some_nums
print some_nums[0]
animals= ['dog', 'cat', 'panda']
print animals[-1]
animals= ['dog', 'cat', 'panda']
print animals.index('cat')
animals= ['dog', 'cat', 'panda']
more_animals = animals+['giraffe']
print more_animals
animals= ['dog', 'cat', 'panda']
more_animals = animals.append('giraffe')
print more_animals
animals= ['dog', 'cat', 'panda']
animals.append("giraffe")
print animals
animals= ['dog', 'cat', 'panda']
for num,animal in enumerate(animals):
print "Number", num+1, "is", animals
animals= ['dog', 'cat', 'panda']
for num,animal in enumerate(animals):
print "Number", num, "is", animal
print "\nWe have", len(animals), "animals in our list."
animals= ['dog', 'cat', 'panda']
while animals:
print animals.pop()
print "\nWe have", len(animals), "animals in our list."