A Concise Introduction to Programming in Python
eBook - ePub

A Concise Introduction to Programming in Python

Mark J. Johnson

Partager le livre
  1. 209 pages
  2. English
  3. ePUB (adapté aux mobiles)
  4. Disponible sur iOS et Android
eBook - ePub

A Concise Introduction to Programming in Python

Mark J. Johnson

DĂ©tails du livre
Aperçu du livre
Table des matiĂšres
Citations

À propos de ce livre

A Concise Introduction to Programming in Python, Second Edition provides a hands-on and accessible introduction to writing software in Python, with no prior programming experience required.

The Second Edition was thoroughly reorganized and rewritten based on classroom experience to incorporate:

  • A spiral approach, starting with turtle graphics, and then revisiting concepts in greater depth using numeric, textual, and image data


  • Clear, concise explanations written for beginning students, emphasizing core principles


  • A variety of accessible examples, focusing on key concepts


  • Diagrams to help visualize new concepts


  • New sections on recursion and exception handling, as well as an earlier introduction of lists, based on instructor feedback

The text offers sections designed for approximately one class period each, and proceeds gradually from procedural to object-oriented design. Examples, exercises, and projects are included from diverse application domains, including finance, biology, image processing, and textual analysis. It also includes a brief "How-To" sections that introduce optional topics students may be interested in exploring.

The text is written to be read, making it a good fit in flipped classrooms. Designed for either classroom use or self-study, all example programs and solutions to odd-numbered exercises (except for projects) are available at: http://www.central.edu/go/conciseintro/.

Foire aux questions

Comment puis-je résilier mon abonnement ?
Il vous suffit de vous rendre dans la section compte dans paramĂštres et de cliquer sur « RĂ©silier l’abonnement ». C’est aussi simple que cela ! Une fois que vous aurez rĂ©siliĂ© votre abonnement, il restera actif pour le reste de la pĂ©riode pour laquelle vous avez payĂ©. DĂ©couvrez-en plus ici.
Puis-je / comment puis-je télécharger des livres ?
Pour le moment, tous nos livres en format ePub adaptĂ©s aux mobiles peuvent ĂȘtre tĂ©lĂ©chargĂ©s via l’application. La plupart de nos PDF sont Ă©galement disponibles en tĂ©lĂ©chargement et les autres seront tĂ©lĂ©chargeables trĂšs prochainement. DĂ©couvrez-en plus ici.
Quelle est la différence entre les formules tarifaires ?
Les deux abonnements vous donnent un accĂšs complet Ă  la bibliothĂšque et Ă  toutes les fonctionnalitĂ©s de Perlego. Les seules diffĂ©rences sont les tarifs ainsi que la pĂ©riode d’abonnement : avec l’abonnement annuel, vous Ă©conomiserez environ 30 % par rapport Ă  12 mois d’abonnement mensuel.
Qu’est-ce que Perlego ?
Nous sommes un service d’abonnement Ă  des ouvrages universitaires en ligne, oĂč vous pouvez accĂ©der Ă  toute une bibliothĂšque pour un prix infĂ©rieur Ă  celui d’un seul livre par mois. Avec plus d’un million de livres sur plus de 1 000 sujets, nous avons ce qu’il vous faut ! DĂ©couvrez-en plus ici.
Prenez-vous en charge la synthÚse vocale ?
Recherchez le symbole Écouter sur votre prochain livre pour voir si vous pouvez l’écouter. L’outil Écouter lit le texte Ă  haute voix pour vous, en surlignant le passage qui est en cours de lecture. Vous pouvez le mettre sur pause, l’accĂ©lĂ©rer ou le ralentir. DĂ©couvrez-en plus ici.
Est-ce que A Concise Introduction to Programming in Python est un PDF/ePUB en ligne ?
Oui, vous pouvez accĂ©der Ă  A Concise Introduction to Programming in Python par Mark J. Johnson en format PDF et/ou ePUB ainsi qu’à d’autres livres populaires dans Computer Science et Programming Games. Nous disposons de plus d’un million d’ouvrages Ă  dĂ©couvrir dans notre catalogue.

Informations

Année
2018
ISBN
9781351621984
Édition
2

CHAPTER 1

Turtle Graphics

This chapter introduces many of the fundamental concepts of computing using examples from turtle graphics.

1.1 GETTING STARTED

Programmable software is what makes a computer a powerful tool. Each different program essentially “rewires” the computer to allow it to perform a different task. By following this text, you will learn basic principles of writing software in the Python programming language.
Python is a popular scripting language available as a free download from www.python.org. Follow the instructions given there to install the latest production version of Python 3 on your system. All examples in this text were written with Python 3.6.
The CPU and RAM
In order to write software, it will be helpful to imagine what happens inside the computer when a program runs. We begin with a rough picture and gradually fill in details along the way.
When a program is ready to run, it is loaded into RAM, usually from long-term storage such as a network drive or flash drive. RAM is an acronym for random access memory, which is the working memory of a computer. RAM is volatile, meaning that it requires electricity to maintain its contents.
Once a program is loaded into RAM, the CPU, or central processing unit, executes the instructions of the program, one at a time. Each CPU family has its own instruction set, and you might be surprised at how limited these instruction sets are. Most instructions boil down to one of a few simple types: load data, perform arithmetic, make comparisons, and store data. It is amazing that these small steps can be combined in so many different ways to build software that is incredibly diverse and complex.
Computer Languages
CPU instruction sets are also known as machine languages. The key point to remember about machine languages is that in order to be run by a CPU, a program must be written in the machine language of that CPU. Unfortunately, machine languages are not meant to be read or written by humans. They are really just specific sequences of bits in memory. (We will explain bits later if you are not sure what they are.)
Because of this, people usually write software in a higher-level language, in the sense of Table 1.1. This ordering is not meant to be precise, but, for example, most programmers would agree that C and C++ are closer to the machine than Python.
TABLE 1.1 Programming language hierarchy
image
Compilation and Interpretation
Now if CPUs can only run programs written in their own machine language, how do we run programs written in Python, Java, or C++? The answer is that the programs are translated into machine language first.
There are two main types of translation: compilation and interpretation. When a program is compiled, it is completely translated into machine language to produce an executable file. C and C++ programs are usually compiled, and most applications you normally run have been compiled. In fact, many companies only distribute compiled executables: unless a project is open source, you do not have access to the uncompiled source code.
On the other hand, when a program is interpreted, it is translated “on-the-fly.” No separate executable file is created. Instead, the translator program (the interpreter) translates your program so that the CPU can execute it. Python programs are usually interpreted.
The Python Interpreter
When you start Python, you are in immediate contact with a Python interpreter. If you provide it with valid Python, the interpreter will translate your code so that it can be executed by the CPU. The interpreter displays the version of Python it was written for, and then shows that it is ready for your input with a “>>>” prompt. The interpreter will translate and execute any legal Python code that is typed at this prompt. For example, if we enter the following statement:
image
the interpreter will respond accordingly. Try it and see.
Remember that if you are not sure what something will do in Python, you can always try it out in the interpreter without having to write a complete program. Experiment—the interpreter will not mind.
A Python Program
That said, our focus will be on writ...

Table des matiĂšres