INTRODUCTION Python is a language that is used by professional programmers Different programming languages are good at doing different things Python can create 3 D graphics for special effects in movies and is often used on web servers to handle searching This book contains all the techniques and ideas you need to know to become a Python programming genius Learn the basics and how to use loops and variables in Python Discover how to create graphics use random numbers and build games simulations and other programs www python org 2 python Before you get started on your programs you'll need to download and install Python on your computer Find out how on page 4 The IDLE Editor is where you will be typing your code The Console is where you will see any text your program outputs as well as information about any bugs Python Turtle Graphics The Turtle Graphics window is where any graphics your program draws will be displayed CODE CAREFULLY AND AVOID THE BUGS Bugs are errors or mistakes in your code that stop your program from working properly Looking for these errors is called debugging Make sure you enter your code very carefully If things aren't working properly see the tips on page 31 to help you Note Words in italics appear in the glossary on 30 page
GETTING STARTED INSTALLING PYTHON First you need to make sure that your computer has the software you need to be able to code with Python Download the newest free version from the Python website There are some apps for tablets that run Python but you will need to use a Mac or PC to do most of these activities Ask permission from the person who owns your computer before you download the software STEPI FIND THE PYTHON WEBSITE www python og Open your web browser and visit www python org Downloads STEP 2 START DOWNLOADING Click the Downloads button near the top of the web page Select a version from the list at the bottom of the page Different versions of Python may be available for your computer This book uses Python 3 5 Make sure you choose a version starting with Python 3 not Python 2 For Windows XP or older versions download Python 3 4 Wait for the download to complete Download Python 3 52 Download Python 3 STEP 3 INSTALL THE SOFTWARE STEP 4 RUN PYTHON Some browsers will then ask you to run the installation program Choose Run If this doesn't happen don't panic The installer file should have been downloaded to your computer Look in your Downloads folder for it Double click it to start installing Python You should get a box giving you instructions on what to do next Follow them to complete the installation On a PC Click Start Programs Python IDLE Or just click IDLE Python if it appears in the recently added section On a Mac Click Finder Applications Click Applications Desktop Double click Python 3 Python 3 Click the IDLE icon Make a shortcut by dragging the IDLE file IDLE onto your dock at the bottom of the desktop Click the icon IDLE
HELLO WORLD SAYING HI When computer programmers start learning a new language the first thing they usually do is learn to make a program that displays a message such as Hello world Let's look at how to do that in Python STEP I RUN IDLE STEP 2 START A NEW FILE Click the File menu then choose New File IDLE File Edit IDLE stands for Integrated Development and Learning Environment This is the program you will use to create your code Click the shortcut to IDLE on your computer See step 4 from page 4 New File Open STEP 3 GET CODING STEP 4 SAVE YOUR CODE Click Save Carefully type in the code shown below The brackets tell Python where the item to display starts and ends Click the IDLE File Edit File menu then Open choose Save Save Type hello as the filename STEP 5 RUN YOUR CODE Click the Run mat Run Optio menu then choose Python Run Module Run Module The print command tells Python to display something The quotation marks tell Python that the item to display is a text string some letters CUSTOMIZE Add more lines to your program Can you make it tell a simple story You must type your code in exactly If you leave out a quotation mark or bracket it will not work IDLE will make parts of your code change color to let you know you have added brackets and quotation marks correctly Python is case sensitive which means you need to use lowercase letters for your commands You'll need to save and run your program steps 4 and 5 each time you add code new