Python_For_Rookies_Answers_2008_Mount.pdf
(
1219 KB
)
Pobierz
Python for Rookies
A First Course in Programming
Answers to Selected Exercises
Sarah Mount, James Shuttleworth and Russel Winder
Australia • Canada • Mexico • Singapore • Spain • United Kingdom • United States
Contents
1 Getting Started 1
Self-Review Questions 1
Programming Exercises 3
Challenges 6
2 The Fundamentals 9
Self-Review Questions 9
Programming Exercises 10
Challenges 15
3 Controlling the Flow 17
Self-Review Questions 17
Programming Exercises 20
Challenges 24
4 Structuring State 27
Self-Review Questions 27
Programming Exercises 29
Challenges 33
5 Functionally Modular 35
Self-Review Questions 35
Programming Exercises 38
Challenges 42
6 Classy Objects 45
Self-Review Questions 45
Programming Exercises 47
Challenges 51
ii
Contents
7 Inheriting Class 55
Self-Review Questions 55
Programming Exercises 56
Challenges 60
8 Filing Things Away 63
Self-Review Questions 63
Programming Exercises 64
Challenges 67
9 Testing, Testing 69
Self-Review Questions 69
Programming Exercises 70
Challenges 76
10 Algorithms and Data Structures 83
Self-Review Questions 83
Programming Exercises 85
Challenges 87
11 Threading the Code 89
Self-Review Questions 89
Programming Exercises 91
Challenges 92
12 The Life of the Game 95
Self-Review Questions 95
Programming Exercises 96
Challenges 97
13 PyGames 99
Self-Review Questions 99
Programming Exercises 100
Challenges 101
Getting Started
1
Self-Review Questions
Self-review 1.1
Why is the following the case?
>>> print 4 + 9
13
>>>
Because the Python system evaluates the expression
4 + 9
which means adding
4
to
9
giving the result
13
which is the printed out.
Self-review 1.2
Why is the following the case – rather than the result being 13?
>>> print "4 + 9"
4+9
>>>
Because
"4+9"
is a string and so it is printed as is, there is no expression to be
evaluated.
Self-review 1.3
Why does the expression
2 + 3 * 4
result in the value
14
and not
the value
24?
Because the
*
operator has higher precedence than the operator
+.
The
3 * 4
subex-
pression is evaluated first giving
12
and then the expression
2 + 12
is evaluated
resulting in
14.
Self-review 1.4
What is a module and why do we have them?
A module is a collection of bits of program that provide a useful service.
Self-review 1.5
What is a library and why do we have them?
The answer “A place where books are held, so that they can be borrowed” is clearly
correct but not the one wanted. The answer wanted is“A collection of bits of
software that we can make use of in our programs.”
Self-review 1.6
What does the statement
turtle.demo ( )
mean?
The statement causes the function
demo
from the Turtle module to be executed.
Self-review 1.7
What is an algorithm?
It is a procedure/process for achieving a desired goal.
Self-review 1.8
Why are algorithms important in programming?
Plik z chomika:
sdfg_ds
Inne pliki z tego folderu:
Introduction_To_Computer_Science_Using_Python_2013_Dierbach.pdf
(58546 KB)
Introduction_To_Computation_And_Programming_Using_Python_2013_Guttag.pdf
(36814 KB)
Practical_Programming_2ed_2013_Gries.pdf
(13554 KB)
Explorations_In_Computing_2014_Conery.pdf
(12295 KB)
Python_Programming_2004_Zelle.pdf
(5582 KB)
Inne foldery tego chomika:
Algorithms
Artificial Intelligence
C
Compilers
Concurrency
Zgłoś jeśli
naruszono regulamin