Skip to content

Commit aa0c3ab

Browse files
committed
Editing
1 parent 6af2fe6 commit aa0c3ab

File tree

3 files changed

+45
-23
lines changed

3 files changed

+45
-23
lines changed

Notes/01_Introduction/01_Python.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
[Contents](../Contents) \| [Next (1.2 A First Program)](02_Hello_world)
2+
13
# 1.1 Python
24

35
### What is Python?
@@ -67,7 +69,7 @@ share. Today, shares of Google are priced at $711.25. Using Python’s
6769
interactive mode as a calculator, figure out how much profit Larry would
6870
make if he sold all of his shares.
6971

70-
```pycon
72+
```python
7173
>>> (711.25 - 235.14) * 75
7274
35708.25
7375
>>>
@@ -77,7 +79,7 @@ Pro-tip: Use the underscore (\_) variable to use the result of the last
7779
calculation. For example, how much profit does Larry make after his evil
7880
broker takes their 20% cut?
7981

80-
```pycon
82+
```python
8183
>>> _ * 0.80
8284
28566.600000000002
8385
>>>
@@ -117,7 +119,7 @@ run, you may have to hit "Return" once after you’ve pasted it in.
117119

118120
Use cut-and-paste to execute the Python statements in this session:
119121

120-
```pycon
122+
```python
121123
>>> 12 + 20
122124
32
123125
>>> (3 + 4
@@ -147,7 +149,7 @@ Try something more advanced and type these statements to find out how
147149
long people waiting on the corner of Clark street and Balmoral in
148150
Chicago will have to wait for the next northbound CTA \#22 bus:
149151

150-
```pycon
152+
```python
151153
>>> import urllib.request
152154
>>> u = urllib.request.urlopen('http://ctabustracker.com/bustime/map/getStopPredictions.jsp?stop=14791&route=22')
153155
>>> from xml.etree.ElementTree import parse
@@ -176,7 +178,7 @@ If your work environment requires the use of an HTTP proxy server, you may need
176178
to set the `HTTP_PROXY` environment variable to make this part of the
177179
exercise work. For example:
178180

179-
```pycon
181+
```python
180182
>>> import os
181183
>>> os.environ['HTTP_PROXY'] = 'http://yourproxy.server.com'
182184
>>>

Notes/01_Introduction/02_Hello_world.md

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
[Contents](../Contents) \| [Previous (1.1 Python)](01_Python) \| [Next (1.3 Numbers)](03_Numbers)
2+
13
# 1.2 A First Program
24

35
This section discusses the creation of your first program, running the
@@ -46,19 +48,24 @@ hello world
4648
>>>
4749
```
4850

49-
This so-called *read-eval* loop is very useful for debugging and exploration.
51+
This so-called *read-eval-print-loop* (or REPL) is very useful for debugging and exploration.
5052

51-
Let's take a closer look at the elements:
53+
**STOP**: If you can't figure out how to interact with Python, stop what you're doing
54+
and figure out how to do it. If you're using an IDE, it might be hidden behind a
55+
menu option or other window. Many parts of this course assume that you can
56+
interact with the interpreter.
57+
58+
Let's take a closer look at the elements of the REPL:
5259

5360
- `>>>` is the interpreter prompt for starting a new statement.
5461
- `...` is the interpreter prompt for continuing a statements. Enter a blank line to finish typing and run the statements.
5562

56-
The `...` prompt may or may not be shown depending on how you are using Python. For this course,
63+
The `...` prompt may or may not be shown depending on your environment. For this course,
5764
it is shown as blanks to make it easier to cut/paste code samples.
5865

5966
The underscore `_` holds the last result.
6067

61-
```pycon
68+
```python
6269
>>> 37 * 42
6370
1554
6471
>>> _ * 2
@@ -94,7 +101,7 @@ bash %
94101

95102
Or from the Windows shell:
96103

97-
```shell
104+
```
98105
C:\SomeFolder>hello.py
99106
hello world
100107
@@ -103,6 +110,8 @@ hello world
103110
```
104111

105112
Note: On Windows, you may need to specify a full path to the Python interpreter such as `c:\python36\python`.
113+
However, if Python is installed in its usual way, you might be able to just type the name of the program
114+
such as `hello.py`.
106115

107116
### A Sample Program
108117

@@ -134,7 +143,8 @@ print('Final height', num_bills * bill_thickness)
134143
When you run it, you get the following output:
135144

136145
```bash
137-
bash % python3 sears.py 1 1 0.00011
146+
bash % python3 sears.py
147+
1 1 0.00011
138148
2 2 0.00022
139149
3 4 0.00044
140150
4 8 0.00088
@@ -197,6 +207,9 @@ height = 442 # Floating point
197207
height = 'Really tall' # A string
198208
```
199209

210+
Python is dynamically typed. The perceived "type" of a variable might change
211+
as a program executes depending on the current value assigned to it.
212+
200213
### Case Sensitivity
201214

202215
Python is case sensitive. Upper and lower-case letters are considered different letters.
@@ -228,11 +241,11 @@ while num_bills * bill_thickness < sears_height:
228241
print('Number of days', days)
229242
```
230243

231-
The statements below the `while` will execute as long as the expression after the `while` is `true`.
244+
The statements indented below the `while` will execute as long as the expression after the `while` is `true`.
232245

233246
### Indentation
234247

235-
Indentation in Python is used to denote a set of statements that go together.
248+
Indentation is used to denote groups of statements that go together.
236249
Consider the previous example:
237250

238251
```python
@@ -244,17 +257,16 @@ while num_bills * bill_thickness < sears_height:
244257
print('Number of days', days)
245258
```
246259

247-
Indentation groups the following statements together as the operations that
248-
execute repeatedly:
260+
Indentation groups the following statements together as the operations that repeat:
249261

250262
```python
251263
print(day, num_bills, num_bills * bill_thickness)
252264
day = day + 1
253265
num_bills = num_bills * 2
254266
```
255267

256-
Because the `print()` statement at the end is not indented, it means
257-
that it does not belong to the loop. The empty line is just for
268+
Because the `print()` statement at the end is not indented, it
269+
does not belong to the loop. The empty line is just for
258270
readability. It does not affect the execution.
259271

260272
### Indentation best practices
@@ -286,8 +298,6 @@ else:
286298
print('Computer says yes')
287299
```
288300

289-
Depending on the values of `a` and `b`, the execution will jump to `print('Computer says no')` or `print('Computer says yes')`.
290-
291301
You can check for multiple conditions by adding extra checks using `elif`.
292302

293303
```python
@@ -324,7 +334,7 @@ name = 'Jake'
324334
print('My name is', name) # Print the text 'My name is Jake'
325335
```
326336

327-
`print()` always puts a new line at the end.
337+
`print()` always puts a newline at the end.
328338

329339
```python
330340
print('Hello')
@@ -364,7 +374,7 @@ print('Your name is', name)
364374
This is useful for small programs, learning exercises or simple debugging.
365375
It is not widely used for real programs.
366376

367-
### `pass` statement
377+
### pass statement
368378

369379
Sometimes you need to specify an empty code block. The keyword `pass` is used for it.
370380

@@ -379,10 +389,19 @@ This is also called a "no-op" statement. It does nothing. It serves as a placeho
379389

380390
## Exercises
381391

392+
This is the first set of exercises where you need to create Python
393+
files and run them. From this point forward, it is assumed that you
394+
are editing files in the `practical-python/Work/` directory. To help
395+
you locate the proper place, a number of empty starter files have
396+
been created with the appropriate filenames. Look for the file
397+
`Work/bounce.py` that's used in the first exercise.
398+
382399
### Exercise 1.5: The Bouncing Ball
383400

384-
A rubber ball is dropped from a height of 100 meters and each time it hits the ground, it bounces back up to 3/5 the height it fell.
385-
Write a program "bounce.py" that prints a table showing the height of the first 10 bounces.
401+
A rubber ball is dropped from a height of 100 meters and each time it
402+
hits the ground, it bounces back up to 3/5 the height it fell. Write
403+
a program `bounce.py` that prints a table showing the height of the
404+
first 10 bounces.
386405

387406
Your program should make a table that looks something like this:
388407

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,4 @@ Bug reports are appreciated and may be filed through the [issue
112112
tracker](https://github.com/dabeaz-course/practical-python/issues).
113113
Pull requests are not accepted except by invitation. Please file an
114114
issue first.
115+

0 commit comments

Comments
 (0)