PYTHON PROGRAMMING: AN INTRODUCTION TO COMPUTER SCIENCE JOHN ZELLE FRANKLIN,BEEDLE ASSOCIATES
PYTHON programming: AN INTRODUCTION TO COMPUTER SCIENCE JOHN ZELLE FRANKLIN, BEEDLE &, ASSOCIATES
PYTHON PROGRAMMING AN INTRODUCTION TO COMPUTER SCIENCE 出 John M.Zelle Wartburg College Franklin,Beedle Associates,Inc.+8536 SW St.Helens Drive,Suite D+Wilsonville,Oregon 97070+503/682-7668 www.fbeedle.com
PYTHON PROGRAMMING AN INTRODUCTION TO COMPUTER SCIENCE ^ JohnM.Zelle Wartburg College Franklin, Beedle &i Associates, Inc. + 8536 SW St. Helens Drive, Suite D + Wilsonville, Oregon 97070 + 503/682-7668 www.fbeedle.com
President and Publisher Jim Leisy (jimleisy@fbeedle.com) Production TomSumner Dean Lake Cover Ian Shadburne Marketing Christine Collier Order Processing Krista Brown Printed in the U.S.A. Names of all products herein are used for identification purposes only and are trade- marks and/or registered trademarks of their respective owners.Franklin,Beedle Asso- ciates,Inc.,makes no claim of ownership or corporate association with the products or companies that own them. 2004 Franklin,Beedle Associates Incorporated.No part of this book may be repro- duced,stored in a retrieval system,transmitted,or transcribed,in any form or by any means-electronic,mechanical,telepathic,photocopying,recording,or otherwise-with- out prior written permission of the publisher.Requests for permission should be ad- dressed as follows: Rights and Permissions Franklin,Beedle Associates,Incorporated 8536 SW St.Helens Drive,Suite D Wilsonville,Oregon 97070 Library of Congress Cataloging-in-Publication data may be obtained from the publisher
President and Publisher Jim Leisy (jimleisy@fbeedle.com) Production TomSumner Dean Lake Cover Ian Shadburne Marketing Christine Collier Order Processing Krista Brown Printed in the U.S.A. Names of all products herein are used for identification purposes only and are trade- marks and/or registered trademarks of their respective owners. Franklin, Beedle & Associates, Inc., makes no claim of ownership or corporate association with the products or companies that own them. ©2004 Franklin, Beedle & Associates Incorporated. No part of this book may be repro- duced, stored in a retrieval system, transmitted, or transcribed, in any form or by any means—electronic, mechanical, telepathic, photocopying, recording, or otherwise—without prior written permission of the publisher. Requests for permission should be addressed as follows: Rights and Permissions Franklin, Beedle & Associates, Incorporated 8536 SW St. Helens Drive, Suite D Wilsonville, Oregon 97070 Library of Congress Cataloging-in-Publication data may be obtained from the publisher
Contents Foreword .X preface X Chapter 1 Computers and Programs 1 1.1 The Universal Machine................. 1.2 Program Power.… 1 3 1.3 What is Computer Science?............. 3 1.4 Hardware Basics… 5 1.5 Programming Languages 6 1.6 The Magic of Python............. 9 1.7 Inside a Python Program.......... 14 1.8 Chaos and Computers 17 1.9 Chapter Summary.… 18 1.10 Exercises.… 20 Chapter 2 Writing Simple Programs 25 2.1 The Software Development Process.......... 25 2.2 Example Program:Temperature Converter 26 2.3 Elements of Programs.......... .29 2.3.1 Names… 29 2.3.2 Expressions 30 2.4 Output Statements… 31 2.5 Assignment Statements. 33 2.5.1 Simple Assignment.. 33 2.5.2 Assigning Input... 5 2.5.3 Simultaneous Assignment 3 2.6 Definite Loops.......... 9 2.7 Example Program:Future Value 42
Contents Foreword ix Preface x Chapter 1 Computers and Programs 1 1.1 The Universal Machine 1 1.2 Program Power 3 1.3 What is Computer Science? 3 1.4 Hardware Basics 5 1.5 Programming Languages 6 1.6 The Magic of Python 9 1.7 Inside a Python Program 14 1.8 Chaos and Computers 17 1.9 Chapter Summary 18 1.10 Exercises 20 Chapter 2 Writing Simple Programs 25 2.1 The Software Development Process 25 2.2 Example Program: Temperature Converter 26 2.3 Elements of Programs 29 2.3.1 Names 29 2.3.2 Expressions 30 2.4 Output Statements 31 2.5 Assignment Statements 33 2.5.1 Simple Assignment 33 2.5.2 Assigning Input 35 2.5.3 Simultaneous Assignment 36 2.6 Definite Loops 39 2.7 Example Program: Future Value 42