12.07.2015 Views

Is Python a

Is Python a

Is Python a

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

a => 1b => 2c => 3d => 4e => 5f => 6g => 7>>> for key in sorted(D): # In more recent <strong>Python</strong>s... print key, '=>', D[key]4. Program logic alternatives. Here’s some sample code for the solutions. Yourresults may vary a bit; this exercise is mostly designed to get you playing withcode alternatives, so anything reasonable gets full credit:L = [1, 2, 4, 8, 16, 32, 64]X = 5i = 0while i < len(L):if 2 ** X == L[i]:print 'at index', ibreaki = i+1else:print X, 'not found'L = [1, 2, 4, 8, 16, 32, 64]X = 5for p in L:if (2 ** X) == p:print (2 ** X), 'was found at', L.index(p)breakelse:print X, 'not found'L = [1, 2, 4, 8, 16, 32, 64]X = 5if (2 ** X) in L:print (2 ** X), 'was found at', L.index(2 ** X)else:print X, 'not found'X = 5L = []for i in range(7): L.append(2 ** i)print LPart III, Statements and Syntax | 655

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

Saved successfully!

Ooh no, something went wrong!