A Concise Introduction to Programming in Python
eBook - ePub

A Concise Introduction to Programming in Python

Mark J. Johnson

Condividi libro
  1. 209 pagine
  2. English
  3. ePUB (disponibile sull'app)
  4. Disponibile su iOS e Android
eBook - ePub

A Concise Introduction to Programming in Python

Mark J. Johnson

Dettagli del libro
Anteprima del libro
Indice dei contenuti
Citazioni

Informazioni sul libro

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/.

Domande frequenti

Come faccio ad annullare l'abbonamento?
È semplicissimo: basta accedere alla sezione Account nelle Impostazioni e cliccare su "Annulla abbonamento". Dopo la cancellazione, l'abbonamento rimarrà attivo per il periodo rimanente già pagato. Per maggiori informazioni, clicca qui
È possibile scaricare libri? Se sì, come?
Al momento è possibile scaricare tramite l'app tutti i nostri libri ePub mobile-friendly. Anche la maggior parte dei nostri PDF è scaricabile e stiamo lavorando per rendere disponibile quanto prima il download di tutti gli altri file. Per maggiori informazioni, clicca qui
Che differenza c'è tra i piani?
Entrambi i piani ti danno accesso illimitato alla libreria e a tutte le funzionalità di Perlego. Le uniche differenze sono il prezzo e il periodo di abbonamento: con il piano annuale risparmierai circa il 30% rispetto a 12 rate con quello mensile.
Cos'è Perlego?
Perlego è un servizio di abbonamento a testi accademici, che ti permette di accedere a un'intera libreria online a un prezzo inferiore rispetto a quello che pagheresti per acquistare un singolo libro al mese. Con oltre 1 milione di testi suddivisi in più di 1.000 categorie, troverai sicuramente ciò che fa per te! Per maggiori informazioni, clicca qui.
Perlego supporta la sintesi vocale?
Cerca l'icona Sintesi vocale nel prossimo libro che leggerai per verificare se è possibile riprodurre l'audio. Questo strumento permette di leggere il testo a voce alta, evidenziandolo man mano che la lettura procede. Puoi aumentare o diminuire la velocità della sintesi vocale, oppure sospendere la riproduzione. Per maggiori informazioni, clicca qui.
A Concise Introduction to Programming in Python è disponibile online in formato PDF/ePub?
Sì, puoi accedere a A Concise Introduction to Programming in Python di Mark J. Johnson in formato PDF e/o ePub, così come ad altri libri molto apprezzati nelle sezioni relative a Computer Science e Programming Games. Scopri oltre 1 milione di libri disponibili nel nostro catalogo.

Informazioni

Anno
2018
ISBN
9781351621984
Edizione
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...

Indice dei contenuti