Make Your Own Python Text Adventure

上传:xl8213449 浏览: 39 推荐: 0 文件:PDF 大小:1.71MB 上传时间:2020-07-30 19:00:38 版权申诉
Table of ContentsChapter 1: Getting StartedChapter 2: Your First ProgramChapter 3: Listening to Your UsersChapter 4: DecisionsChapter 5: FunctionsChapter 6: ListsChapter 7: LoopsChapter 8: ObjectsChapter 9: ExceptionsChapter 10: IntermezzoChapter 11: Building Your WorldChapter 12: MakingMake Your Own Python Text AdventurePhillip johnsonNew york, usaISBN-13(pbk):978-1-4842-3230-9ISBN-13( electronic:978-1-4842-3231-6htos:// doi. org/10.1007/978-1-4842-3231-6Library of Congress Control Number: 2017960887Copyright o 2018 by Phillip JohnsonThis work is subject to copyright. All rights are reserved by the Publisher, whether the whole orpart of the material is concerned, specifically the rights of translation, reprinting, reuse ofillustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way,and transmission or information storage and retrieval, electronic adaptation, computer softwareor by similar or dissimilar methodology now known or hereafter developedTrademarked names, logos, and images may appear in this book. Rather than use a trademarksymbol with every occurrence of a trademarked name, logo, or image we use the names, logos,and images only in an editorial fashion and to the benefit of the trademark owner, with nointention of infringement of the trademarkThe use in this publication of trade names, trademarks, service marks, and similar terms, even ifthey are not identified as such, is not to be taken as an expression of opinion as to whether or notthey are subject to proprietary rightsWhile the advice and information in this book are believed to be true and accurate at the date ofpublication, neither the authors nor the editors nor the publisher can accept any legalresponsibility for any errors or omissions that may be made. The publisher makes no warranty,express or implied, with respect to the material contained hereinCover image designed by FreepikManaging Director: Welmoed SpahrEditorial director: Todd greenAcquisitions Editor: Todd greenDevelopment Editor: James MarkhamTechnical reviewer: Tri PhanCoordinating editor: Jill BalzanoCopy Editor: Kezia EndsleyCompositor: SPi GlobalIndexer: SPi globalArtist: SPi globalDistributed to the book trade worldwide by Springer Science+Business Media New York,233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax(201)348-4505e-mailorders-ny@springer-sbm.com,orvisitwww.springeronline.comApressMediaLlcisaCalifornia LLC and the sole member (owner) is Springer Science +Business Media Finance Inc(SSBM Finance Inc). SSBM Finance Inc is a Delaware corporationForinformationontranslations,pleasee-mailrights@apress.com,orvisithttp://www.apress.com/rights-permissionsApress titles may be purchased in bulk for academic, corporate, or promotional use e Bookversions and licenses are also available for most titles. For more information reference our printandebookBulkSaleswebpageathttp://www.apress.com/bulk-salesAny source code or other supplementary material referenced by the author in this book is availabletoreadersonGithubviathebooksproductpagelocatedatwww.apress.com/9781484232309Formoredetailedinformationpleasevisithttp://www.apress.com/source-code.Printed on acid-free paperTable of contentsAbout the author…uixAbout the technical reviewer■■■■■■Chapter 1: Getting Started mmm mmmmmmnrntroducti0n…1Who this book is forHow To use this bookSetting Up Your Workspace..... menemenPython Versions4Installing PythonVerify Your Installation .mamChapter 2: Your First Program■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■Creating a Module .nmenemnmnnnnnemennennnn 10Writing Code…,..,.10Running Python ProgramsHomework,……12Chapter 3: Listening to Your Users■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■13Your friends: stdout and stdinReading from Standard Input15Saving information15Data Types…,,,.Homework18TABLE OF CONTENTSChapter 4: Decisions nmmmmamImaI 19BooleansIf-statements2Boolean operations……24Homework,……26Chapter 5: Functionsg27Data n data outHomework32Chapter 6: Lists.■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■a■■33What is a list?…33Common List Operations……35Add35Length35Get36Search.……136Adding Lists to the Game38HomeworkChapter 7: Loops41Whille LoopsF0r- Each Loops…43L00 o Counters,,,.,.,.,.,.,.,.,.,.,,,Ranges.,...,....,,,45Using EnumerateNesting…,,,,,,,,,,The Game Loop……Homework…152TABLE OF CONTENTSChapter8:0 bjects,,,…,,,,,:,::,:,::::53Object Members53Defining Objects with ClassesUsing_ inito to Initialize objectsUsing__str 0 to Print Objects.mmmamammammmmammammmmmmnmn 57Adding Weapons to the Game mmmemennmemmmnnaamemnn.mn. 6(A Dash of object-Oriented Programming .Homework64Chapter 9: Exceptions mammmamaan65Validating User Input65Checking object Members.Raising Exceptions Intentionally.Homework70Chapter 10: Intermezzo■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■a■■■■■■■口■■Organizing Code Into Multiple FilesImporting from other Files.mmmnamamaanmemnnnmnnnmmn. 75Homework76Chapter11: Building Your World,,…,…,,,,…,;77TheX- Y Grid…,Moving in the World81Chapter 12: Making the World More Interesting ma85Enemies….85Do You have any potions.OrF000?.……93TABLE OF CONTENTSChapter 13: World-Building Part 2. amamamImIImII 99DictionariesCreating a Dictionary.Get100Add/Update....101Delete102L00p.……102Limiting Actions103Expanding the World.......nChapter 14: Econ 101■■■■■■■■ga115Share the wealth,115Giving the Trader a Home118Expanding the World122Chapter 15: Endgame■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■127Finishing UpWhat next?.mm. 129Add more features to the gameMake Your Job Easier with Python Scripts...........130Write a Web application mnmnnmenamnaeaanaeenanennn 130ppendix A: Homework Solutions■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■131Chapter2: Your First program…….,,,,,,,,…131Chapter 3: Listening to Your Users132Chapter 4: Decisions.m...............m.133Chapter 5: Functions134Chapter 6: Lists135TABLE OF CONTENTSChapter7:L0ops…........,,137Chapter 8: objects139Chapter9: Exceptions……143Appendix B: Common Errors.ammmmmmmmmammmmmamn 145Attribute error145Name error145TypeError…,,,,,,,,,,,146Index147About the authorPhillip johnson is a software developerbased out of columbus, ohio. he has workedon projects ranging from call center queuingto bioinformatics and has used a wide rangeof technologies, including Python, Java,Scala, and SQL. He blogs at Let's Talk Data(http://letstalkdata.comAbout the technical reviewerTri Phan is the founder of the ProgrammingLearning Channel on YouTube. He has over10 years of experience in the software industry.He has outsourced for many companies andcan write applications in many fields and inmany programming languages, including PHPJava, and C#. In addition, he has over 10 yearsof experience teaching at internationalprogramming training centers like Aptech,NIIT, and Kent College
上传资源
用户评论