Appendix A. Answers to Selected Exercises
5. loops and numbers
a)
i = 0
while i < 11:
i = i + 1
b)
for i in range(11): pass
6. conditionals
n = int(raw_input('enter a number: ')) if n < 0: print 'negative' elif n > 0: print 'positive' else: print 'zero'
7.
s = raw_input('enter a string: ') for eachChar in s: print eachChar for i in range(len(s)): print s[i]
8.
subtot = 0 for i in range(5): subtot = subtot + int(raw_input('enter a number: ')) print subtot
7. identifiers
40XL | number | |
$saving$ | symbol | |
kw | ||
0x40L | number | |
big-daddy | symbol | |
2hot2touch | number | |
thisIsn'tAVar | symbol | |
if | kw | |
counter-1 | symbol |
6. difference between type(a) == type(b) and type(a) is type(b):
type(a) == type(b) whether the value of type(a) is the same ...
Get Core Python Programming now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.