(eBook PDF) Building Python Programs 1st Edition pdf download
(eBook PDF) Building Python Programs 1st Edition pdf download
download
https://ebookluna.com/product/ebook-pdf-building-python-
programs-1st-edition/
https://ebookluna.com/product/ebook-pdf-fundamentals-of-python-first-
programs-2nd-edition/
https://ebookluna.com/download/fundamentals-of-python-first-programs-2nd-
edition-ebook-pdf/
(eBook PDF) Building Java Programs: A Back to Basics Approach 5th Edition
https://ebookluna.com/product/ebook-pdf-building-java-programs-a-back-to-
basics-approach-5th-edition/
Building Java Programs: A Back to Basics Approach 4th Edition (eBook PDF)
https://ebookluna.com/product/building-java-programs-a-back-to-basics-
approach-4th-edition-ebook-pdf/
Building Java Programs: A Back to Basics Approach 4th Edition Stuart Reges
- eBook PDF
https://ebookluna.com/download/building-java-programs-a-back-to-basics-
approach-ebook-pdf/
Building Java Programs - A Back to Basics Approach 5th Edition Stuart Reges
- eBook PDF
https://ebookluna.com/download/building-java-programs-a-back-to-basics-
approach-ebook-pdf-2/
https://ebookluna.com/download/progress-in-heterocyclic-chemistry-ebook-
pdf/
https://ebookluna.com/download/python-distilled-ebook-pdf/
(eBook PDF) Building Java Programs: A Back to Basics Approach 4th Edition
by Stuart Reges
https://ebookluna.com/product/ebook-pdf-building-java-programs-a-back-to-
basics-approach-4th-edition-by-stuart-reges/
Preface
The Python programming language has become enormously popular in recent years.
Many people are impressed with how quickly you can learn Python’s simple and intui-
tive syntax and that has led many users to create popular libraries. Python was designed
by Guido van Rossum who has been affectionaly dubbed “Benevolent Dictator For Life
(BDFL)” by the Python community. He has said that he chose the name Python because
he was “in a slightly irreverent mood” and that he is “a big fan of Monty Python’s
Flying Circus” (a British comedy show). Who wouldn’t want to learn a programming
language named after a group of comedians?
Our new Building Python Programs text is designed for use in a first course in com-
puter science. We have class-tested it with hundreds of undergraduates at the University
of Arizona, most of whom were not computer science majors. This textbook is based
on our previous text, Building Java Programs, now in its fourth edition. The Java text
has proven effective in our class testing with thousands of students including our own
at the University of Washington since 2007.
Introductory computer science courses have a long history at many universities
of being “killer” courses with high failure rates. But as Douglas Adams says in The
Hitchhiker’s Guide to the Galaxy, “Don’t panic.” Students can master this material if
they can learn it gradually.
Python has many attributes that make it an appealing language for a first computer
science course. It has a simple and concise yet powerful syntax that makes it pleasant
to learn and great for writing many common programs. A student can write their first
Python program with only a single line of code, as opposed to several lines in most other
languages such as Java or C++. Python includes a built-in interpreter and read-evaluate-
print loop (REPL) for quickly running and testing code, encouraging students to test and
explore the language. Python also offers a rich set of libraries that students can use for
graphics, animation, math, scientific computing, games, and much more. This text has
been built from the start for Python 3, the most modern version of the language as of this
writing, and it embraces the modern features and idioms of that version of the language.
Our teaching materials are based on a “back to basics” approach that focuses on
procedural programming and program decomposition. This is also called the “objects
later” approach, as opposed to the “objects early” approach taught in some schools. We
know from years of experience that a broad range of scientists, engineers, and others
can learn how to program in a procedural manner. Once we have built a solid founda-
tion of procedural techniques, we turn to object-oriented programming. By the end of
the text, students will have learned about both styles of programming.
iii
Brief Contents
xi
Contents
Arithmetic Operators 62
Precedence 66
Mixing and Converting Types 69
2.2 Variables 70
A Program with Variables 74
Increment/Decrement Operators 79
Printing Multiple Values 80
2.3 The for Loop 83
Using a Loop Variable 87
Details about Ranges 90
String Multiplication and Printing Partial Lines 94
Nested for Loops 98
2.4 Managing Complexity 101
Scope 101
Pseudocode 103
Constants 108
2.5 Case Study: Hourglass Figure 111
Problem Decomposition and Pseudocode 112
Initial Structured Version 114
Adding a Constant 115
Images 188
Procedural Decomposition with Graphics 189
3.5 Case Study: Projectile Trajectory 191
Unstructured Solution 195
Structured Solution 196
Graphical Version 199
Introduction
1.1 Basic Computing Concepts
■■ Why Programming?
This chapter begins with a review of some basic terminology about comput- ■■ Hardware and Software
ers and computer programming. Many of these concepts will come up in later ■■ The Digital Realm
chapters, so it will be useful to review them before we start delving into the
■■ The Process of Programming
■■ Why Python?
details of how to program in Python. ■■ The Python Programming
Environment
We will begin our exploration of Python by looking at simple programs
1.2 And Now: Python
that produce text output to a console window. This discussion will allow us
■■ Printing Output
to explore many elements that are common to all Python programs, while ■■ String Literals (Strings)
working with programs that are fairly simple in structure. ■■ Escape Sequences
■■ Printing a Complex Figure
After we have reviewed the basic elements of Python programs, we will ■■ Comments, Whitespace, and
explore the technique of procedural decomposition by learning how to break Readability
up a Python program into several functions. Using this technique, we can 1.3 Program Errors
break up complex tasks into smaller subtasks that are easier to manage and ■■ Syntax Errors
■■ Logic Errors (Bugs)
we can avoid redundancy in our program solutions.
1.4 Procedural Decomposition
■■ Functions
■■ Flow of Control
■■ Identifiers and Keywords
■■ Functions That Call Other
Functions
■■ An Example Runtime Error
Chapter Summary
Self-Check Problems
Exercises
Programming Projects
1
2 Chapter 1 Introduction to Python Programming
Why Programming?
At most universities, the first course in computer science is a programming course.
Many computer scientists are bothered by this because it leaves people with the impres-
sion that computer science is programming. While it is true that many trained computer
scientists spend time programming, there is a lot more to the discipline. So why do we
study programming first?
A Stanford computer scientist named Don Knuth answers this question by saying
that the common thread for most computer scientists is that we all in some way work
with algorithms.
Algorithm
A step-by-step description of how to accomplish a task.
It has often been said that a person does not really understand something until
after teaching it to someone else. Actually a person does not really understand
something until after teaching it to a computer, i.e., expressing it as an
algorithm.1
1
Knuth, Don. Selected Papers on Computer Science. Stanford. CA: Center for the Study of Language and
Information, 1996.
1.1 Basic Computing Concepts 3
Program
A list of instructions to be carried out by a computer.
One key feature that differentiates a computer from a simpler machine like a calculator
is its versatility. The same computer can perform many different tasks (playing games,
computing income taxes, connecting to other computers around the world), depending
on what program it is running at a given moment. A computer can run not only the pro-
grams that exist on it currently, but also new programs that haven’t even been written yet.
The physical components that make up a computer are collectively called hardware.
One of the most important pieces of hardware is the central processing unit, or CPU.
The CPU is the “brain” of the computer: It is what executes the instructions. Also
important is the computer’s memory (often called random access memory, or RAM,
because the computer can access any part of that memory at any time). The computer
uses its memory to store programs that are being executed, along with their data. RAM
is limited in size and does not retain its contents when the computer is turned off.
Therefore, computers generally also use a hard disk as a larger permanent storage area.
Computer programs are collectively called software. The primary piece of soft-
ware running on a computer is its operating system. An operating system provides an
environment in which many programs may be run at the same time; it also provides
4 Chapter 1 Introduction to Python Programming
a bridge among those programs, the hardware, and the user (the person using the
computer). The programs that run inside the operating system are often called
applications or apps.
When the user selects a program for the operating system to run (e.g., by double-
clicking the program’s icon on the desktop), several things happen: The instructions for
that program are loaded into the computer’s memory from the hard disk, the operating
system allocates memory for that program to use, and the instructions to run the pro-
gram are fed from memory to the CPU and executed sequentially.
Digital
Based on numbers that increase in discrete increments, such as the integers
0, 1, 2, 3, etc.
Binary Number
A number composed of just 0s and 1s, also known as a base-2 number.
Humans generally work with decimal or base-10 numbers, which match our physiol-
ogy (10 fingers and 10 toes). However, when we were designing the first computers,
we wanted systems that would be easy to create and very reliable. It turned out to be
simpler to build these systems on top of binary phenomena (e.g., a circuit being open or
closed) rather than having 10 different states that would have to be distinguished from
one another (e.g., 10 different voltage levels).
From a mathematical point of view, you can store things just as easily using binary
numbers as you can using base-10 numbers. But since it is easier to construct a physical
device that uses binary numbers, that’s what computers use.
This does mean, however, that people who aren’t used to computers find their
conventions unfamiliar. As a result, it is worth spending a little time reviewing how
Discovering Diverse Content Through
Random Scribd Documents
Ilec vi la porte cassée:
Ge ne l'oi pas plustost passée,
Qu'Amors trovai dedens la porte,
Et son ost qui confort m'aporte.
Diex! quel avantage me firent
Li vassal qui la desconfirent!
De Diex et de saint Benéoist
Puissent-il estre benéoist!
Ce fut Faus-Semblant li traïstres,
Le fils Barat, li faus menistres
Dame Ypocrisie sa mere,
Qui tant est as vertus amere,
Et dame Astenance-Contrainte,
Qui de Faus-Semblant est enceinte,
Preste d'enfanter Antecrist,
Si cum ge truis où livre escrit.
Cil là desconfirent sans faille;
Si pri por eus vaille que vaille.
[p.325]
15509. Et plus à mon aise respire,
Ayant naguère entendu dire
Que Malebouche gisait mort.
Onc tel plaisir n'eus d'une mort.
Là je vis la porte cassée;
Je ne l'eus pas plutôt passée
due je trouvai le Dieu d'Amours
Menant son ost à mon secours.
Dieu! quel service me rendirent
Ces amis qui la déconfirent!
Que de Dieu et de saint Benoît
Ils soient bénis pour leur exploit!
C'était Faux-Semblant, fils sinistre
D'Hypocrisie et faux ministre,
Dont le père Mensonge était
Qui tant vertu combat et hait,
Puis dame Abstinence-Contrainte
Des uvres de Semblant enceinte,
Prête d'enfanter Antechrist,
Comme au saint livre il est écrit.
Adonc pour eux, vaillent que vaillent,
Prière fais, puisqu'ils bataillent
Et la porte ont brisée pour moi.
Celui qui veut, traître et sans foi,
Tromper les gens et parjure être,
De Faux-Semblant fasse son maître,
D'Abstinence suive la loi,
Simple se feigne et double soit.
Quand cette porte que j'ai dite
Vis ainsi prise et déconfite,
L'ost trouvai rassemblé céans
Prêt à l'assaut, mes yeux voyants.
Si ma félicité fut grande,
Doux Dieu! que nul ne le demande!
[p.326]
LXXVII
[p.327]
LXXVII
[p.328]
Bel-Acueil.
L'Amant.
[p.329]
Bel-Accueil.
Grâces vous rends, dit-il, beau Sire,
Et de même je veux vous dire:
Si j'ai rien que vous désiriez,
Je veux aussi qu'aise en ayez,
Tout bien, tout honneur, tire à tire,
Comme-moi prenez-en donc, sire.
L'Amant.
[p.330]
[p.331]
LXXVIII
Danger à l'Amant.
15449.
Jà n'i viengne-il sainte, ne saint,
Vassal, vassal, se Diex me saint,
A poi que ge ne vous affronte.
L'Amant.
[p.333] 15629.
L'Amant.
[p.334]
[p.335]
[p.336]
[p.337]
[p.338]
15547.
Mar l'éussiés-vous tant véu,
Par li sommes tuit decéu.
L'Acteur.
Lors le prennent et tant le batent,
Que fuiant en la tor l'embatent,
Où l'ont, après tant de ledures,
A trois paires de serréures,
Sans plus metre n'en fers, n'en clos,
Sous trois paires de clez enclos.
A cele fois plus nel' greverent,
Mès c'iert por ce qu'il se hasterent,
Si li promistrent de pis faire,
Quant se seront mis au repaire.
LXXIX
L'Auteur.
LXXIX
[p.340]
[p.341]
[p.342]
Dangier.
[p.343]
Danger.
[p.344]
L'Amant.
L'Amant.
L'Amant.
L'Amant.
LXXX
LXXX
L'Amant.
L'Amant.
LXXXI
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebookluna.com