ebook img

The Python Coding Manual PDF

194 Pages·2019·125.45 MB·English
by  
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview The Python Coding Manual

ERC mes cli BDM’'S {ree ace Manual Series thon Manual Coding Guides @ Massive Code Step-by-step Python3 Repository @ £12.99 Volume20 US$24.99 9 Can$25.99 7 7 Aus$25.25 2 0 NZ$29.99 5 6 6 6 6 0 Leam 0 4 hon Black Media Sat Dog To continue learning more about your tech visit us at: 7 www.bdmpublications.com — ws ~W\ , " : Mac, MacBook & Watch or Lightroom ( ig odin EXCLUSIVE Offers on iPhone Raspberry Pi GuideBook fo python rBeginne® our Tech Guidebooks re on Ae J Print & digital editions @ Featuring the very latest updates Step-by-step tutorials and guides h Adobe, Created by BDM experts tosho anual Check out our latest titles today! SPECIAL DEALS» a and Bonus Content sitsima e Sign up to our monthly newsletter bdmpublications.com/ultimate-photoshop and get the latest updates, offers Buy our Photoshop guides and download tutorial and news from BDM. We are here images for free! Simplysign up and get creative. to help you Master Your Tech! Toy else 27°=-k&&g. addClass("hidden") ;return!0}).on("focus", funct EN eC aon ast umethor rene. ement ane AoA as torte mL iol filters some Ss Saw LinerimeAHO HEH Sy, : : wot we ! pDM's Manual Sees } uithon Manual Coding The Only Python Manual You Need... Anyone can learn how to code. All it takes is time, patience, and a good guide to help you get started. From there, you can take your coding experience as Farasyou like, but the most important Factor is building a good Foundation. This manual aims to helpyou build a knowledge base around one ofthe best programming languages available: Python. Python is a Fantastic programming language thathastaken theworldbystorm. It’seasytouse, powerful,useful,andFun. ltworkswithotherprogramminglanguages,and with all the major computer operating systems and platforms available today. It’stheidealchoiceforentry-levelprogrammerswhowanttolearn anewskill, orsimplywant to discover howtheycan createsomething on the computer that works For them, and it’s used by data scientists and engineerswho demand complexityand power. Within these pages are the essential tutorials thatwill help you progress through the process of building your First piece of code, to tackling variables, numbers and expressions, user input, Python modules, and buildingandmanipulating listsofdata.We'veevenincludedasectioncalled the Code Repository, covering a huge range ofdifferent types of Python programming,which you're Free to delve into and use inyourown unique programs.Learning PythonisgreatFun,sowhatareyouwaiting For? Let'sgetcoding! ei @bdmpubs BDM Publications www.bdmpublications.com | ED) contents) ontents The Manual Python Coding ~~ oom 36 38 Starting Python forthe FirstTime 40 Your FirstCode 42 Savingand ExecutingYourCode 44 Executing Code from the Command Line 46 Numbersand Expressions 48 Using Comments 8 Being a Programmer 50 WorkingwithVariables 10 ABriefHistoryofCoding 52 UserInput 12 Choosing a Programming Language 54 Creating Functions 14 Creating aCoding Platform 56 Conditionsand Loops 16 UsingVirtualMachines 58 Python Modules 18 Equipment Will Need You 60 Python Errors Ore 62 Combining WhatYou KnowSo Far ar) ee BN PerBear 7.) OES a 64 eT a ee ee t| ry 7. 7 eeageee l 7 | Canaan Manipulating Data AD pela rates @ tape)! a5nrereeh aaa 20 66 Lists nas 68 Tuples Welcome to Python 70 Dictionaries 72 Splitting andJoining Strings 22 WhyPython? 74 FormattingStrings ~~ 24 WhatcanYou Dowith Python? 76 DateandTime ~~ 26 Pythonin Numbers 78 Opening Files 28 HowtoSetUpPython inWindows 80 Writing toFiles 30 HowtoSetUpPython in Linux 82 Exceptions 32 Python on the Pi 84 Python Graphics 34 Getting toKnow Python 86 Combining WhatYou KnowSoFar 4 BDM’sManualSerie-sVolume 20 Dog Contents MasterPythonwith the help ofourFantasticCode Repository, Featuring code forgames, toolsand more.See page 148 formore details. | oa i 148 % WwW 90 CalendarModule 150 Python File Manager 92 OSModule 152 NumberGuessing Game 94 Using the MathModule 154 Polygon Circles 96 Random Module 155 Random NumberGenerator 98 TkinterModule 156 Random Password Generator 100 Pygame Module 157 Keyboard Drawing Script 104 BasicAnimation 158 PygameTextExamples 106 CreateYourOwn Modules 159 GoogleSearchScript 160 Textto BinaryConvertor 162 TextAdventureScript 164 MouseControlledTurtle 165 PythonAlarmClock Learning Linux 166 VerticallyScrollingText 168 Python DigitalClock 170 PythonScrollingTickerScript 110 Whatis Linux? 171 SimplePython Calculator 112 Why Linux? 172 Playing Musicwith the Winsound Module 114 Using the Filesystem 174 HangmanGameScript 116 Listing and Moving Files 118 Creating and Deleting Files 120 Createand Remove Directories 122 Copying, Moving and Renaming Files 124 Using theMan Pages 126 EditingTextFiles 176te 128 Getting to KnowUsers 130 Ownershipand Permissions Coding Projects & Tips 132 UsefulSystem and DiskCommands 134 Managing Programsand Processes 178 Creatinga Loading Screen 136 Input, Outputand Pipes 180 TextAnimations 138 FunThings to Doin theTerminal 182 Tracking the ISSwith Python 140 More FunThingstoDoin theTerminal 186 UsingTextFilesforAnimation 142 LinuxTipsandTricks 188 PassingVariablestoPython 144 Command LineQuick Reference 190 Python Beginner's Mistakes 146 A-ZofLinuxCommands 192 GlossaryofPythonTerms www.bdmpublications.com 5 Index j Wy Y Wns CG 7] | th A G Z Giles ay Yj ea YY GG UUia; 447) UA bbe We oe VA 4 q \A \N dy ale YA r4 v4 aa= =oOcS36vvG=wuv \ if A -Volume20 CH ( Print (“The World ofCode”) Where tostart learning howtocode? Remarkably, thisisthemostdifficult step.There are plentyofprogramming languagesoutthere,and aseemingly unlimited numberoftools to helpyou achievewhatyouwant; butwheredo you begin? In thissection,we lookatwhatyouwill need to take those Firsttentative steps into theworld ofcoding.Youwon't suddenly become a programmerin twenty-fourhours, learning howtocode properlytakes timeand patience. But with little help,you can masterthe a basicsandstartyourcodingjourney. Being a Programmer 10 ABriefHistoryofCoding 12 Choosing a Programming Language 14 Creating a Coding Platform ~— 16 UsingVirtualMachines 18 EquipmentYouWill Need www.bdmpublications.com CH ( Being a Programmer MORE THAN CODE Forthoseofyouoldenoughtorememberthe‘80s,thegoldeneraofhome computing,theworldofcomputingwas verydifferentscenetohowitis a today.8-bitcomputersthatyoucouldpurchaseasawhole,asopposedto beinginkitFormandyouhaving tosolderthepartstogether,werethestuff ofdreams;andgettingyourhandsononewassheerblisscontainedwithin alargeplasticbox.However,itwasn’tsomuchthenewtechnologythat computersthenoffered,moreoveritwasthefactthatfortheFirsttime ever,youcouldcontrolwhatwasbeingviewedonthe‘television’. Lie Insteadofsimplyplayingoneofthethousandsofgamesavailableatthe Timeshavechangedsinceprogramminginthe‘80s, time,manyusersdecidedtheywantedtocreatetheirowncontent,their butthecorevaluesstillremain. owngames;orsimplysomethingthatcouldhelpthemwiththeirhomework orhomeFinances.Thesimplicityofthe8-bithomecomputermeantthat “It's creatingsomethingFromafewlinesofBASICcodewasachievableandso to you theFirstgenerationofhome-bredprogrammerwasborn. up how far to take Fromthatpointon,programmingexpandedexponentially.Itwasn’tlong beforethebedroomcoderwasathingofthepastandhugeteamsof designers,coders,artistsandmusicianswereinvolvedinmakingasingle game.Thisofcourseledtotheprogrammerbecomingmorethansimply your coding someonewhocouldfashionaspriteonthescreenandmakeitmoveatthe pressofakey. adventure!” Naturally,timehasmovedonandwithitthetechnologythatweuse. However,thefundamentalsofprogramming remainthesame;butwhat exactlydoesittaketobeaprogrammer? sinclude<staia.h> s#iinncclluuddeec<stddo.lhisb>.n> Thesinglemostcommontraitofanyprogrammer,regardlessofwhat #include<conio.h> they'redoing,istheabilitytoseealogicalpattern.Bythiswemean void getup() t someonewhocanlogicallyfollowsomethingfromstarttoFinishand textcolor(BLACK); textbackground(15); envisagetheintendedoutcome.Whileyoumaynotfeelyou'resucha clrser(); window(16,2,78,3)3 person,itispossibletotrainyourbrainintothiswayofthinking.Yes,it cprintf(“PressXtoExit, Press SpacetoJump"); window(62,2,80,3); takestimebutonceyoustarttothinkinthisparticularwayyouwillbeable cprint#("SCORE : "); window(1,25,86,25); toconstructandFollowcode. for(int x=0;x<793x++) cprintf("n"); textcolor(®); t Secondtologicisanunderstandingofmathematics.Youdon’thavetobe int t,speede49; atageniuslevelbut youdoneedtounderstandtherudimentsofmaths. void ds(int jump=@) t MathsisallaboutbeingabletosolveaproblemandcodemostlyFallsunder static int a=1; theumbrellaofmathematics. if(jump==@) t=O; else if(jump==2) te-5 Beingabletoseethebigpictureiscertainlybeneficialforthemodern welisnedot+w+(;2,15-t,18,25); programmer.Undoubtedly,asaprogrammer,youwillbepartofateam ceeeccpppppprrrrrriiiiiinnnnnnttttttffffff((((((*""“"“ aana sanannAamaanuananunarunnuanintnananmnn"ea*™*m))))3");53;5 oobeffodeetxhspeiegrncpteerrdos,gtraoallmcormefawetrheso,amasnmadraemltcoerrleeeamtthienangntaloikFfeintlhyaalptparfriontdaoulfcpatr.noWdevhueiclnte,byboieguignemgraatybelaoemntloy cepprriinntt:f(" mannanannnan nn **))5; understandwhateveryoneelseisdoingwillhelpyoucreatesomething ief(pjurminptf=(="1 ||AajunmApn==2){ : that'sultimatelybetterthansimplybeinglockedinyourowncodingcubicle. cprintt(" sy one ")3 yelse if(a==1) { eprintf(“ naan nan “ys Finally,there’salsoalevelofcreativityneededtobeagoodprogrammer. cprintt(* aM *) 322; Againthough,youdon’tneedtobeacreativegenius, justhavethe e+lse if(a==2) imaginationtobeabletoseetheendproductandhowtheuserwillinteract t cprintf(“ namna *)5 withit. cprintf(" "); a=l; aM c+printt(” "ys Thereisofcoursealotmoreinvolvedinbeingaprogrammer,including delay(speed); learningtheactualcodeitself.However,withtime,patienceandthe v+oid obj() f determinationtolearn,anyonecanbecomeaprogrammer.Whether youwanttobepartofatriple-Avideogameteamorsimplycreatean automatedroutinetomakeyourcomputinglifeeasier,it'suptoyou how Fartotakeyourcodingadventure! www.bdmpublications.com fb of A History Coding It’seasy to think that programming a machine toautomate a process orcalculate avalue is amodern concept that’s only really happened in the last Fiftyyears orso. However, thatassumption is quite wrong, coding has actually been around forquite some time. f 01000011 01101111 01100100 01100101 Essentiallyallformsofcodingaremadeupofonesandzeros,onorof takai. Thisworks For amoderncomputerandeven theoldestknowncomputationaldeye - ~87 BC ~850 AD 1800 1842-1843 1930-1950 It'sdifficulttopinpointanexact ) start of whenhumansbeganto ‘program’adevice.However, it’swidelyacceptedthatthe AntikytheraMechanismispossibly theFirst‘coded’artefact.It’s datedtoabout87BCandisan ancientGreekanaloguecomputer andorreryusedtopredict Loe ae Yh / astronomical positions. GY, OAwL i! ey | ae AES, a ey AdaLovelacetranslated thememoirsoftheItalian mathematician,Francis we aD Maneclang,regarding CharlesBabbage’s AnalyticalEngine.She madecopiousnoteswithin (pens) methodofcalculating BernoulliNumbers usingtheengine.Thisis TIN, recognisedastheFirst computerprogram.Not bad,consideringthere werenocomputers availableatthetime.

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.