PY THON - Weebly

1y ago
22 Views
2 Downloads
5.38 MB
562 Pages
Last View : Today
Last Download : 3m ago
Upload by : Carlos Cepeda
Transcription

PY THON LEARN PYTHON— FAST! In the first half of the book, you’ll learn about basic programming concepts, such as lists, dictionaries, classes, and loops, and practice writing clean and readable code with exercises for each topic. You’ll also learn how to make your programs interactive and how to test your code safely before adding it to a project. In the second half of the book, you’ll put your new knowledge into practice with three substantial projects: a Space Invaders–inspired arcade game, data visualizations with Python’s super-handy libraries, and a simple web app you can deploy online. As you work through Python Crash Course, you’ll learn how to: Use powerful Python libraries and tools, including matplotlib, NumPy, and Pygal Make 2D games that respond to keypresses and mouse clicks, and that grow more difficult as the game progresses Work with data to generate interactive visualizations Create and customize simple web apps and deploy them safely online Deal with mistakes and errors so you can solve your own programming problems If you’ve been thinking seriously about digging into programming, Python Crash Course will get you up to speed and have you writing real programs fast. Why wait any longer? Start your engines and code! ABOUT THE AUTHOR Eric Matthes is a high school science and math teacher living in Alaska, where he teaches an introductory Python course. He has been writing programs since he was five years old. COVERS PYTHON 2 AND 3 PY THON CR A SH COURSE Python Crash Course is a fast-paced, thorough introduction to programming with Python that will have you writing programs, solving problems, and making things that work in no time. T H E F I N E ST I N G E E K E N T E RTA I N M E N T “ I L I E F L AT .” 39.95 ( 45.95 CDN) SHELVE IN: PROGRAMMING LANGUAGES/ PYTHON This book uses RepKover — a durable binding that won’t snap shut MATTHES w w w.nostarch.com CR ASH COURSE A H A N D S - O N , P R O J E C T - B A S E D I N T R O D U C T I O N T O P R O G R A M M I N G ERIC MAT THES

Python Crash Course

Python Crash Course A Hands-On, Project-Based Introduction to Programming b y E r ic M a t t h e s San Francisco

Python Crash Course. Copyright 2016 by Eric Matthes. All rights reserved. No part of this work 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 the prior written permission of the copyright owner and the publisher. First printing 19 18 17 16 15   1 2 3 4 5 6 7 8 9 ISBN-10: 1-59327-603-6 ISBN-13: 978-1-59327-603-4 Publisher: William Pollock Production Editor: Riley Hoffman Cover Illustration: Josh Ellingson Interior Design: Octopod Studios Developmental Editors: William Pollock, Liz Chadwick, and Leslie Shen Technical Reviewer: Kenneth Love Copyeditor: Anne Marie Walker Compositor: Riley Hoffman Proofreader: James Fraleigh For information on distribution, translations, or bulk sales, please contact No Starch Press, Inc. directly: No Starch Press, Inc. 245 8th Street, San Francisco, CA 94103 phone: 415.863.9900; info@nostarch.com www.nostarch.com Library of Congress Cataloging-in-Publication Data Matthes, Eric, 1972Python crash course : a hands-on, project-based introduction to programming / by Eric Matthes. pages cm Includes index. Summary: "A project-based introduction to programming in Python, with exercises. Covers general programming concepts, Python fundamentals, and problem solving. Includes three projects - how to create a simple video game, use data visualization techniques to make graphs and charts, and build an interactive web application"-- Provided by publisher. ISBN 978-1-59327-603-4 -- ISBN 1-59327-603-6 1. Python (Computer program language) I. Title. QA76.73.P98M38 2015 005.13'3--dc23 2015018135 No Starch Press and the No Starch Press logo are registered trademarks of No Starch Press, Inc. Other product and company names mentioned herein may be the trademarks of their respective owners. Rather than use a trademark symbol with every occurrence of a trademarked name, we are using the names only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. The information in this book is distributed on an “As Is” basis, without warranty. While every precaution has been taken in the preparation of this work, neither the author nor No Starch Press, Inc. shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the information contained in it.

About the Author Eric Matthes is a high school science and math teacher living in Alaska, where he teaches an introductory Python course. He has been writing programs since he was five years old. Eric currently focuses on writing software that addresses inefficiencies in education and brings the benefits of open source software to the field of education. In his spare time he enjoys climbing mountains and spending time with his family. About the Technical Reviewer Kenneth Love has been a Python programmer and teacher for many years. He has given talks and tutorials at conferences, done professional trainings, been a Python and Django freelancer, and now teaches for an online education company. Kenneth is also the co-creator of the django-braces package, which provides several handy mixins for Django’s class-based views. You can keep up with him on Twitter at @kennethlove.

For my father, who always made time to answer my questions about programming, and for Ever, who is just beginning to ask me his questions

Brief Contents Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxvii Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxix Part I: Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Chapter 1: Getting Started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 Chapter 2: Variables and Simple Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 Chapter 3: Introducing Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 Chapter 4: Working with Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 Chapter 5: if Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75 Chapter 6: Dictionaries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95 Chapter 7: User Input and while Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117 Chapter 8: Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133 Chapter 9: Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161 Chapter 10: Files and Exceptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189 Chapter 11: Testing Your Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215 Part II: Projects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231 Project 1: Alien Invasion Chapter 12: A Ship That Fires Bullets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235 Chapter 13: Aliens! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265 Chapter 14: Scoring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 291

Project 2: Data Visualization Chapter 15: Generating Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 321 Chapter 16: Downloading Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 349 Chapter 17: Working with APIs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 377 Project 3: Web Applications Chapter 18: Getting Started with Django . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 397 Chapter 19: User Accounts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 427 Chapter 20: Styling and Deploying an App . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 455 Afterword . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 483 Appendix A: Installing Python . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 485 Appendix B: Text Editors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 491 Appendix C: Getting Help . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 499 Appendix D: Using Git for Version Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 505 Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 515 x   Brief Contents

Conte nt s in De ta il Acknowledgments xxvii Introduction xxix Who Is This Book For? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxx What Can You Expect to Learn? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxx Why Python? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxxi Part I: Basics 1 1 Getting Started 3 Setting Up Your Programming Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Python 2 and Python 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Running Snippets of Python Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Hello World! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Python on Different Operating Systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Python on Linux . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Python on OS X . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Python on Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Troubleshooting Installation Issues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Running Python Programs from a Terminal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . On Linux and OS X . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . On Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Exercise 1-1: python.org . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Exercise 1-2: Hello World Typos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Exercise 1-3: Infinite Skills . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 . 4 . 4 . 4 . 5 . 5 . 8 10 15 16 16 16 17 17 17 17 2 Variables and Simple Data Types 19 What Really Happens When You Run hello world.py . . . . . . . . . . . . . . . . . . . . . . . . . Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Naming and Using Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Avoiding Name Errors When Using Variables . . . . . . . . . . . . . . . . . . . . . . . . Exercise 2-1: Simple Message . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Exercise 2-2: Simple Messages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Changing Case in a String with Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . Combining or Concatenating Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Adding Whitespace to Strings with Tabs or Newlines . . . . . . . . . . . . . . . . . . . Stripping Whitespace . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Avoiding Syntax Errors with Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Printing in Python 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Exercise 2-3: Personal Message . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Exercise 2-4: Name Cases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Exercise 2-5: Famous Quote . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 20 21 21 23 23 23 24 25 26 26 28 29 29 29 29

Exercise 2-6: Famous Quote 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Exercise 2-7: Stripping Names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Integers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Floats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Avoiding Type Errors with the str() Function . . . . . . . . . . . . . . . . . . . . . . . . . . Integers in Python 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Exercise 2-8: Number Eight . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Exercise 2-9: Favorite Number . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . How Do You Write Comments? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . What Kind of Comments Should You Write? . . . . . . . . . . . . . . . . . . . . . . . . . Exercise 2-10: Adding Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . The Zen of Python . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Exercise 2-11: Zen of Python . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 Introducing Lists 37 What Is a List? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Accessing Elements in a List . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Index Positions Start at 0, Not 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Using Individual Values from a List . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Exercise 3-1: Names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Exercise 3-2: Greetings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Exercise 3-3: Your Own List . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Changing, Adding, and Removing Elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Modifying Elements in a List . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Adding Elements to a List . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Removing Elements from a List . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Exercise 3-4: Guest List . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Exercise 3-5: Changing Guest List . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Exercise 3-6: More Guests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Exercise 3-7: Shrinking Guest List . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Organizing a List . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Sorting a List Permanently with the sort() Method . . . . . . . . . . . . . . . . . . . . . . Sorting a List Temporarily with the sorted() Function . . . . . . . . . . . . . . . . . . . . Printing a List in Reverse Order . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Finding the Length of a List . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Exercise 3-8: Seeing the World . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Exercise 3-9: Dinner Guests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Exercise 3-10: Every Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Avoiding Index Errors When Working with Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Exercise 3-11: Intentional Error . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 Working with Lists Looping Through an Entire List . . . . . . . . . . . . A Closer Look at Looping . . . . . . . . . Doing More Work Within a for Loop . Doing Something After a for Loop . . . xii   Contents in Detail 29 29 30 30 30 31 32 33 33 33 33 33 34 34 36 36 37 38 39 39 40 40 40 40 40 41 42 46 46 46 47 47 47 48 49 49 50 50 50 50 52 52 53 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 54 55 56

Avoiding Indentation Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Forgetting to Indent . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Forgetting to Indent Additional Lines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Indenting Unnecessarily . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Indenting Unnecessarily After the Loop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Forgetting the Colon . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Exercise 4-1: Pizzas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Exercise 4-2: Animals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Making Numerical Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Using the range() Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Using range() to Make a List of Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . Simple Statistics with a List of Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . List Comprehensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Exercise 4-3: Counting to Twenty . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Exercise 4-4: One Million . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Exercise 4-5: Summing a Million . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Exercise 4-6: Odd Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Exercise 4-7: Threes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Exercise 4-8: Cubes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Exercise 4-9: Cube Comprehension . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Working with Part of a List . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Slicing a List . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Looping Through a Slice . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Copying a List . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Exercise 4-10: Slices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Exercise 4-11: My Pizzas, Your Pizzas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Exercise 4-12: More Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Tuples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Defining a Tuple . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Looping Through All Values in a Tuple . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Writing over a Tuple . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Exercise 4-13: Buffet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Styling Your Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . The Style Guide . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Indentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Line Length . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Blank Lines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Other Style Guidelines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Exercise 4-14: PEP 8 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Exercise 4-15: Code Review . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 if Statements A Simple Example . . . . . . . . . . . . . . . . . . . . . . . . . Conditional Tests . . . . . . . . . . . . . . . . . . . . . . . . . . Checking for Equality . . . . . . . . . . . . . . . . Ignoring Case When Checking for Equality . Checking for Inequality . . . . . . . . . . . . . . . Numerical Comparisons . . . . . . . . . . . . . . Checking Multiple Conditions . . . . . . . . . . Checking Whether a Value Is in a List . . . . . 57 57 58 59 59 60 60 60 61 61 62 63 63 64 64 64 64 64 64 64 65 65 66 67 69 69 69 69 69 70 71 71 72 72 72 73 73 73 74 74 74 75 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76 76 76 77 78 78 79 80 Contents in Detail   xiii

Checking Whether a Value Is Not in a List . . . . . . . . . . . . . . . . . . . . . . . . . . Boolean Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Exercise 5-1: Conditional Tests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Exercise 5-2: More Conditional Tests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . if Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Simple if Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . if-else Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . The if-elif-else Chain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Using Multiple elif Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Omitting the else Block . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Testing Multiple Conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Exercise 5-3: Alien Colors #1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Exercise 5-4: Alien Colors #2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Exercise 5-5: Alien Colors #3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Exercise 5-6: Stages of Life . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Exercise 5-7: Favorite Fruit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Using if Statements with Lists . . . . . .

CCRR ASH COURSEASH COURSE SHELVE IN: PROGRAMMING LANGUAGES/ PYTHON 39.95 ( 45.95 CDN) FAST! LEARN PYTHON—— PYTHON CRASH COURSE PYTHON CRASH COURSE MATTHES COVERS PYTHON 2 AND 3 Python Crash Course is a fast-paced, thorough intro-duction to programming with Python that will have you writing programs, solving problems, and making things

Related Documents:

THON merch will also be available online at store.thon.org. All profits ben-efit THON. Committee applications close Friday, Sept. 20, and many THON organizations are still open to those who want to join. Looking to the future, THON will host its THON 5K on Oct. 13, the 100 Days Til THON

finally got to our 8th grade Walk-A-Thon, we were thrilled! So far, the walk-a-thon has been my favorite event in 8th grade, and we made such unforgettable and wonderful memories! Page 4 2016 WALK-A-THON NICOLE LUBI-17, Issue 1 On October 6th, the Class of 2017 partici-pated in their last Walk-A-Thon at St. Augustine. All of the the 8th .

Updated October 2022 Page 1 HOW TO HOST A BY THE PEOPLE TRANSCRIBE-A-THON What's a transcribe-a-thon? By the People invites you to contribute to public knowledge by transcribing Library of Congress digital collections at crowd.loc.gov. This is a guide for how (and why) to run a By the People transcribing event. A transcribe-a-thon can be.

submitted by Anne Beard . winner of the state 4-H Sewing Skill-a-thon in the senior division. Kenton County Green Junior 4-H Skill-a-thon team took first place in the junior division. Webster County Junior 4-H Skill-a-thon

math skills while learning the importance of helping others. Developed in association with Scholastic, the St. Jude Math-A-Thon program: Meets Common Core State Standards Challenges your kids with engaging math activities Prov

THON through my friends at Phoenixville, who are leaders there. Once I realized what the cause was, I couldn’t be-lieve that we didn’t have it at PV. It was a cause we needed to be a part of.” Beard explained. The Mini-THON club at the high school first met on April 12, 2019 and curre

A Wikipedia Edit-a-thon with Elizabeth Galoozis Monday, March 8th, 2-4pm n H l Zoom Link (USC Libraries) Telling the Whole Story: A Wikipedia Edit-a-thon Wikipedia’s content and contributors remain unrepresentative of the world

The annual Hoop-A-Thon fundraiser became a virtual event called the Hoop-A-Thon at Home. Students found creative ways to participate from home and raised over 11,000 for the school! From learning new platforms and technologies to organizing virtual field trips, our teachers