15.04.2013 Views

Core Python Programming (2nd Edition)

Core Python Programming (2nd Edition)

Core Python Programming (2nd Edition)

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

or<br />

print i, s[i]<br />

for i, x in enumerate(s):<br />

print i, x<br />

8. Loops and operators<br />

subtot = 0<br />

for i in range(5):<br />

subtot += int(raw_input('enter a number: '))<br />

print subtot<br />

or<br />

# uses sum() BIF and generator expressions<br />

print sum(int(raw_input('enter a number: ')) for i in range(5))

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!