






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!







x = seq[0]" print x" x = seq[1]" print x" …" x = seq[len(seq)-1]" print x The for-loop: for x in seq:" print x
§ loop sequence: seq § loop variable : x § body : print x § Also called repetend
print 'Before while' count = 0 i = 0 while i < 3: print 'Start loop '+i count = count + I i = i + 1 print 'End loop ' print 'After while'
Before while Start loop 0 End loop Start loop 1 End loop Start loop 2 End loop After while
Must remember to increment
Have to know in advance where to stop
i = 0 while i < len(t):
if t[i] == 3: del t[i] else: i += 1 Sometimes you want to modify the sequence Stopping point keeps changing
while 3 in t: t.remove(3) Maybe this one is easier with no numerical counter
def sqrt(c): x = c/ while abs(xx – c) > 1e-6: x = x / 2 + c / (2x) return x Sometimes your termination condition has nothing to do with counters