-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChapter02.html
More file actions
118 lines (99 loc) · 4.37 KB
/
Chapter02.html
File metadata and controls
118 lines (99 loc) · 4.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Chapter 2</title>
<meta http-equiv="content-type"
content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<h1>Chapter 2</h1>
Contents: <a href="#TrueFalse">True/False</a> | <a
href="#Multiple_Choice">Multiple Choice</a> | <a href="#Discussion">Discussion</a>
| <a href="#Programming_Exercises">Programs</a><br>
<br>
<h2><a name="TrueFalse"></a>True/False</h2>
<ol>
<li>False</li>
<li>True<br>
</li>
<li>False (most programs change as they are maintained)</li>
<li>True</li>
<li>False</li>
<li>True</li>
<li>True</li>
<li>False</li>
<li>True</li>
<li>False<br>
</li>
</ol>
<h2><a name="Multiple_Choice"></a>Multiple Choice</h2>
<ol>
<li>c<br>
</li>
<li>a</li>
<li>d</li>
<li>c</li>
<li>b</li>
<li>b</li>
<li>b</li>
<li>d</li>
<li>a</li>
<li>d</li>
</ol>
<h2><a name="Discussion"></a>Discussion</h2>
<ol>
<li>Actual answers will vary, but should have some description
of each step. The six steps are: Problem Analysis, Specification, Design,
Implementation, Testing/Debugging, and Maintenance.</li>
<li> The problem does not ask students to distinguish between
programmer chosen names and keywords, so there may be some variation in approach.
In this solution, "Regular" identifiers are in red, keyword identifiers in
green, and expressions are underlined.
<pre># File: chaos.py (comment)<br># A simple program illustrating chaotic behavior. (comment)<br><br><font
color="#00ff00"><it>def</it></font> <font color="#ff0000"><it>main</it></font>(): #(function definition)<br> <font
color="#00ff00">print</font>( <u>"This program illustrates a chaotic function"</u>) #(output)<br> <font
color="#ff0000">x</font> = <u><font color="#00ff00">eval</font>(<font color="#00ff00">input</font>("Enter a number between 0 and 1: "))</u> #(input)<br> <font
color="#ff0000"><font color="#00ff00">for</font> i <font
color="#00ff00">in</font> <font color="#00ff00"><u>range</u></font></font><u>(10)</u>: #(for loop)<br> <font
color="#ff0000">x</font> = <u>3.9 * <font color="#ff0000">x</font> * (1 - <font
color="#ff0000">x</font>) </u> #(assignment)<br> <font
color="#ff0000"><font color="#00ff00">print</font>(<u>x</u>)</font> #(output)<br><br><font
color="#ff0000">main</font>()</pre>
</li>
<li> A Python for loop implements a definite loop. A counted loop
is a specific kind of definite loop that is designed to iterate as certain
number of times.</li>
<li>These can be checked interactively.</li>
<ol>
<li>
<pre>0<br>1<br>4<br>9<br>16</pre>
</li>
<li>
<pre>3 1 4 1 5</pre>
</li>
<li>
<pre>Hello<br>Hello<br>Hello<br>Hello<br></pre>
</li>
<li>
<pre>0 1<br>1 2<br>2 4<br>3 8<br>4 16</pre>
</li>
</ol>
<li>It's eaiser to create an algorithm without worrying about all
the syntactic details of a language.<br>
</li>
<li>The <tt>sep</tt> parameter supplies the text that is inserted between
the printed expressions.</li>
<li> Since the loop body executes 0 times, the code will produce:
<pre>
start
end
</pre>
</li>
</ol>
<h2><a name="Programming_Exercises"></a>Programming Exercises</h2>
<a href="code/chapter02">Code for Chapter 2 Exercises</a><br>
<br>
<br>
</body>
</html>