Mike McGrath Coding for Beginners In easy steps is an imprint of In Easy Steps Limited 16 Hamilton Terrace Holly Walk Leamington Spa Warwickshire CV32 4LY www.ineasysteps.com Copyright 2015 by In Easy Steps Limited. All rights reserved. No part of this book may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage or retrieval system, without prior written permission from the publisher. Notice of Liability Every effort has been made to ensure that this book contains accurate and current information. However, In Easy Steps Limited and the author shall not be liable for any loss or damage suffered by readers as a result of any information contained herein. Contents Preface The creation of this book has provided me, Mike McGrath, a welcome opportunity to produce an introduction to coding computer programs for readers with no previous coding experience. Contents Preface The creation of this book has provided me, Mike McGrath, a welcome opportunity to produce an introduction to coding computer programs for readers with no previous coding experience.
Although this is a book for beginners, it goes beyond the mere basics so some topics may be more easily understood after gaining some coding experience with the simpler listed programs. All the examples demonstrate coding features using the popular Python programming language and the books screenshots illustrate the actual results produced by executing the listed code. Conventions in this book In order to clarify the code listed in the steps given in each example, I have adopted the same default colorization convention provided by Pythons code editor. Keywords of the Python language itself are colored orange, built-in function names are purple, coder-specified function names are blue, text strings are green, comments are red, and all other code is black, like this: # A function to display a greetingdef greet ( reader ) :print ( Welcome to Coding for Beginners , reader ) Additionally, in order to identify each source code file described in the steps, an icon and file name appears in the margin alongside the steps, like this: program.py Grabbing the source code For convenience I have placed source code files from the examples featured in this book into a single ZIP archive. You can obtain the complete archive by following these easy steps: Browse to www.ineasysteps.com then navigate to Free Resources and choose the Downloads section Find Coding for Beginners in easy step s in the list, then click on the hyperlink entitled All Code Examples to download the archive Now, extract the archive contents to any convenient location on your computer Getting started Welcome to the exciting, fun world of computer coding! This chapter describes how to create your own programming environment and demonstrates how to code your very first program. Programming code A computer is merely a machine that can process a set of simple instructions very quickly.
The set of instructions it processes is known as a program, and the instructions are known as code. People who write computer programs are known as programmers or coders. Their programs have enabled computers to become useful in almost every area of modern life: In the hand computers are found in cellphone devices for tasks such as communication via voice, text, and social media In the home computers are found in household devices such as TV sets, gaming consoles, and washing machines In the office computers are found in desktop devices for tasks such as word processing, payroll, and graphic design In the store computers are found in retail devices such as automatic teller machines (ATMs) and bar code scanners In the car computers are found in control devices for tasks such as engine management, anti-lock braking and security In the sky computers are found in airplanes for piloting and in air traffic control centers for safe navigation These are, in fact, just a few examples of how computers affect our lives today. Yet, computers are really dumb! They can only count from zero to one, and cannot think for themselves. A computer is a collection of electronic components collectively known as hardware. To make the computer function it must be given a set of program instructions known as software.
It is important that each computer program provides clear step-by-step instructions that the computer can execute without errors. The coder must therefore break down the task required of the computer into simple unambiguous steps. For example, a program to move a mobile robot from indoors to outdoors must include instructions to have the robot locate a doorway and navigate around any obstacles. So the coder must always consider what possible unexpected difficulties a program may encounter. Program instructions must be presented to the computer in a language it can understand. At the most basic level the computer can understand machine code, which moves items around in its memory to perform tasks.
This type of obscure low-level code is incredibly tedious as it requires many lines of instruction to perform even a simple task. Fortunately, over the years, many high-level programming languages have been developed that allow the coder to compose instructions in more human-readable form. These modern high-level programs are automatically translated into the machine code that the computer can understand by a compiler or by an interpreter. In order to become a coder you must typically learn at least one of these high-level programming languages: C a powerful compiled language that is closely mapped to machine code and used to develop operating systems C++ an enhanced compiled language developing on C to provide classes for Object Oriented Programming (OOP) C# a modern compiled language designed by Microsoft for the .NET framework and Common Language Infrastructure Java a portable compiled language that is designed to run on any platform regardless of the hardware architecture Python a dynamic interpreted language that allows both functional and Object Oriented Programming (OOP) Programs written in an interpreted language can be run immediately but those written in compiled languages must first be compiled before they can be run. Just as human languages have similarities, such as verbs and nouns, these programming languages have certain similarities as they each possess data structures, in which to store information, and control structures that determine how the program proceeds. Python is a total package of batteries included. Python is a total package of batteries included.
Next page