Adventures in Python - Craig Richardson - E-Book

Adventures in Python E-Book

Craig Richardson

0,0
15,99 €

oder
-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.
Mehr erfahren.
Beschreibung

The complete beginner's guide to Python, for young people who want to start today Adventures in Python is designed for 11-to 15-year olds who want to teach themselves Python programming, but don't know where to start. Even if you have no programming experience at all, this easy to follow format and clear, simple instruction will get you up and running quickly. The book walks you through nine projects that teach you the fundamentals of programming in general, and Python in particular, gradually building your skills until you have the confidence and ability to tackle your own projects. Video clips accompany each chapter to provide even more detailed explanation of important concepts, so you feel supported every step of the way. Python is one of the top programming languages worldwide, with an install base in the millions. It's a favourite language at Google, YouTube, the BBC, and Spotify, and is the primary programming language for the Raspberry Pi. As an open-source language, Python is freely downloadable, with extensive libraries readily available, making it an ideal entry into programming for the beginner. Adventures in Python helps you get started, giving you the foundation you need to follow your curiosity. * Start learning Python at its most basic level * Learn where to acquire Python and how to set it up * Understand Python syntax and interpretation for module programming * Develop the skills that apply to any programming language Python programming skills are invaluable, and developing proficiency gives you a head start in learning other languages like C++, Objective-C, and Java. When learning feels like fun, you won't ever want to stop - so get started today with Adventures in Python.

Sie lesen das E-Book in den Legimi-Apps auf:

Android
iOS
von Legimi
zertifizierten E-Readern

Seitenzahl: 308

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



This edition first published 2015

© 2015 Craig Richardson

Registered office

John Wiley & Sons Ltd, The Atrium, Southern Gate, Chichester, West Sussex, PO19 8SQ, United Kingdom

For details of our global editorial offices, for customer services and for information about how to apply for permission to reuse the copyright material in this book please see our website at www.wiley.com.

The right of the author to be identified as the author of this work has been asserted in accordance with the Copyright, Designs and Patents Act 1988.

All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, electronic, mechanical, photocopying, recording or otherwise, except as permitted by the UK Copyright, Designs and Patents Act 1988, without the prior permission of the publisher.

Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not be available in electronic books.

Designations used by companies to distinguish their products are often claimed as trademarks. All brand names and product names used in this book are trade names, service marks, trademarks or registered trademarks of their respective owners. The publisher is not associated with any product or vendor mentioned in this book. This publication is designed to provide accurate and authoritative information in regard to the subject matter covered. It is sold on the understanding that the publisher is not engaged in rendering professional services. If professional advice or other expert assistance is required, the services of a competent professional should be sought.

Trademarks: Wiley and the Wiley logo are trademarks or registered trademarks of John Wiley & Sons, Inc. and/or its affiliates in the United States and/or other countries, and may not be used without written permission. Python is a registered trademark of the PSF (Python Software Foundation). Raspberry Pi and the Raspberry Pi Logo are a registered trademark of the Raspberry Pi Foundation, which is a UK registered charity. All other trademarks are the property of their respective owners. John Wiley & Sons, Ltd. is not associated with any product or vendor mentioned in the book.

A catalogue record for this book is available from the British Library.

ISBN 978-1-118-95179-8 (paperback); ISBN 978-1-118-95184-2 (ePub); 978-1-118-95185-9 (ePDF)

To the swans on the river Cam. May you never visit the Fellows of St John's College.

Publisher’s Acknowledgments

Some of the people who helped bring this book to market include the following:

 

Editorial and Production

VP Consumer and Technology Publishing Director: Michelle Leete

Associate Director–Book Content Management: Martin Tribe

Associate Publisher: Jim Minatel

Series Creator: Carrie Anne Philbin

Executive Editor: Craig Smith

Project Editor: Kezia Endsley

Copy Editor: Kezia Endsley

Technical Editor: Alex Bradbury

Editorial Manager: Jodi Jensen

Senior Project Editor: Sara Shlaer

Editorial Assistant: Claire Johnson

Proofreader: Wordsmith Editorial

Marketing

Marketing Manager: Lorna Mein

Marketing Assistant: Polly Thomas

About the Author

CRAIG RICHARDSON is a freelance software developer and writer based in the UK. When Craig first started using computers in his early teens he had a typing speed of one word a minute and successfully broke several machines. Since then he’s studied computer science and software development at school and university and has taught hundreds of people to program with Python. He also now knows how to fix the many computers he breaks.

Acknowledgments

This book would not have been possible without the support of my friends and family. Cambridge Make Space has been invaluable: the reliability of the old Internet connection really helped me finish the book. I’d also like to thank the book’s editors and members of staff at Wiley for their hard work.

Adventures in Python®

Contents

Cover

Title Page

About the Author

Introduction

What Is Programming?

What Is Python and What Can You Do With It?

Who Should Read This Book?

What You Will Learn

What You Will Need for the Projects

How This Book Is Organised

Setting Up Python

Creating Your First Program

The Companion Website

Conventions

Reaching Out

Adventure 1: Diving into Python

What Is Programming?

Opening IDLE

Returning to Your First Python Program

It Isn’t Working—Grrr!

Using a File Editor

Asking Questions with Variables

Making the Program Make Decisions: Conditionals

Repeating Code with Loops

Praise Generator

A Bigger Adventure: Spaceship Control Console

Adventure 2: Drawing with Turtle Graphics

Getting Started with Turtle

Using Variables to Change Angles and Lengths

Using Addition to Draw a Spiral

Saving Some Space with Loops

A Shape with 360 Sides: Drawing a Circle

Creating Functions to Reuse Your Code

Shape Presets

Adding Randomly Generated Pictures

Adventure 3: Windows, Buttons, and Other GUI Stuff

Creating Buttons

Creating Text Boxes

Building a Random Sentence Generator

Programming a Guessing Game

Adventure 4: More GUI Elements with Tkinter

Creating Sliders

How Colours Work on Computers and as Hexadecimal Values

Changing the Canvas Colour

Making the Colour Picker

Adding a Text Box

Creating a Click Speed Game

Adventure 5: Drawing Shapes with PyGame

Installing PyGame

My First PyGame

Creating Rectangles

Creating Ellipses

Saving Your Images

Adventure 6: Adding Keyboard Input with PyGame

Using Keyboard Input

Other Keys You Can Use

Creating the Game

Adventure 7: Creative Ways to Use a Mouse with PyGame

Getting the Mouse Position

Making a Mesh

Creating Mouse Trails

Adventure 8: Using Images with PyGame

Loading an Image

Adding a Moustache to a Photograph

Making Sprites

Adventure 9: Using Sounds and Music with PyGame

Playing Sounds

Using Music with Python

Adding Sounds and Music to a Game

Adventure 10: Your Really Big Adventure

Writing the Program for the Game

Debugging the Game

Summary

Appendix A: Installing and Downloading the Proper Files

Installing PyGame

Downloading the Files for Adventures 8, 9 and 10

Glossary

End User License Agreement

List of Tables

Chapter 4

Table 4-1 A List of Python Keywords That Cannot Be Used for the Names of Variables, Functions and Arguments

Table 4-2 A Selection of Colours and Their Hexadecimal Values

Chapter 6

Table 6-1 Keyboard Control Codes in

PyGame

List of Illustrations

Introduction

FIGURE I-1 The code of a program that generates a circular progress bar. You will learn how to create programs like this one in your adventures.

FIGURE I-2 Downloading Python for Windows 8

FIGURE I-3 Python has been installed on Windows 8.

FIGURE I-4 IDLE installed and Python opened on Windows 8

FIGURE I-5 Downloading Python for Windows 7

FIGURE I-6 Python has been installed on Windows 7.

FIGURE I-7 IDLE installed and Python opened on Windows 7

FIGURE I-8 Downloading Python for Mac OS X

FIGURE I-9 Installing Python on a Mac

FIGURE I-10 Python has been installed on the Mac

FIGURE I-11 IDLE installed and Python opened on Mac

FIGURE I-12 The installation process in Linux

FIGURE I-13 Installing IDLE on Linux

FIGURE I-14 IDLE installed and Python opened on Linux

FIGURE I-15 After you press the Enter key, the text inside the speech marks appears on the next line of the Python shell

FIGURE I-16 The phrase appears on every line of the shell

Chapter 1

FIGURE 1-1 IDLE is ready for you to start programming!

FIGURE 1-2 The command prompt in a Python shell

FIGURE 1-3 Your first Python program running in the Python shell

FIGURE 1-4 An error message in the Python shell

FIGURE 1-5 The IDLE file editor window

FIGURE 1-6 The completed program and output in IDLE

FIGURE 1-7 The command prompt waiting for you to input a name

FIGURE 1-8 The finished program

FIGURE 1-9 The finished program running alongside the Python code

FIGURE 1-10 An

if

statement nested inside another

if

statement

FIGURE 1-11 Replying “yes” to the first question will cause the program to ask a second question.

FIGURE 1-12 The finished vending machine code and the Python shell waiting for you to make a choice

FIGURE 1-13 This program repeats until the user types

exit

.

FIGURE 1-14 The loop makes the code repeat infinitely.

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!