If
For-loop
# Make sure that you use while-loops sparingly. Usually a for-loop is better.
# Python expects you to indent something after you end a line
with a : (colon).
if people < cats:
print "Too many cats! The world is doomed!"
if cars > people:
print "We should take the cars."
elif cars < people:
print "We should not take the cars."
else:
print "We can't decide."
if people > buses:
print "Alright, let's just take the buses."
else:
print "Fine, let's stay home then."
For-loop
the_count = [1, 2, 3, 4, 5]
for number in the_count:
print "This is count %d" % number
elements = []
for i in range(0, 6):
print "Adding %d to the list." % i
elements.append(i)
for i in elements:
print "Element was: %d" % i
# Make sure that you use while-loops sparingly. Usually a for-loop is better.