Example: bankruptcy

A Practical Introduction to Python Programming - Brian …

A Practical Introduction toPython ProgrammingBrian HeinoldDepartment of Mathematics and Computer ScienceMount St. Mary s Universityii 2012 Brian HeinoldLicensed under a Creative Commons Attribution-Noncommercial-Share Alike Unported Li-censeContentsI Basics11 Getting Python .. first program .. things in .. input ..92 For .. loop variable .. Trickier Example .. 153 and Decimal Numbers .. Operators .. of operations .. numbers .. functions .. help from Python .. the Shell as a Calculator .. 234 If Simple Example .. operators .. Mistakes .. 30iiiivCONTENTS5 Miscellaneous Topics .. variables .. and mins .. debugging .. programs .. 406 .. and repetition .. individual characters of a string .. methods .. characters .. Examples .. Exercises.

Jan 12, 2022 · A Practical Introduction to Python Programming Brian Heinold Department of Mathematics and Computer Science Mount St. Mary’s University

Tags:

  Introduction, Programming, Python, Practical, Practical introduction to python programming

Information

Domain:

Source:

Link to this page:

Please notify us if you found a problem with this document:

Other abuse

Transcription of A Practical Introduction to Python Programming - Brian …

1 A Practical Introduction toPython ProgrammingBrian HeinoldDepartment of Mathematics and Computer ScienceMount St. Mary s Universityii 2012 Brian HeinoldLicensed under a Creative Commons Attribution-Noncommercial-Share Alike Unported Li-censeContentsI Basics11 Getting Python .. first program .. things in .. input ..92 For .. loop variable .. Trickier Example .. 153 and Decimal Numbers .. Operators .. of operations .. numbers .. functions .. help from Python .. the Shell as a Calculator .. 234 If Simple Example .. operators .. Mistakes .. 30iiiivCONTENTS5 Miscellaneous Topics .. variables .. and mins .. debugging .. programs .. 406 .. and repetition .. individual characters of a string .. methods .. characters .. Examples .. Exercises.

2 517 .. to strings .. functions .. methods .. 628 More with and therandommodule .. comprehensions .. list comprehensions .. lists .. 72 CONTENTSv9 While .. loops .. else statement .. guessing game, more nicely done .. 8310 Miscellaneous Topics ,int,float, andlist.. Booleans .. Shortcuts .. Short-circuiting .. Continuation .. String formatting .. Nested loops .. Exercises .. 9511 Basics .. Dictionary examples .. Working with dictionaries .. Counting words .. Exercises .. 10412 Text Reading from files .. Writing to files .. Examples .. Wordplay .. Exercises .. 11313 Basics .. Arguments .. Returning values .. Default arguments and keyword arguments .. Local variables .. Exercises .. 12514 Object-Oriented Python is objected-oriented.

3 Creating your own classes .. Inheritance .. A playing-card example .. A Tic-tac-toe example .. Further topics .. Exercises .. 138II Graphics14115 GUI Programming with Basics .. Labels .. Entry boxes .. Buttons .. Global variables .. Tic-tac-toe .. 14916 GUI Programming Frames .. Colors .. Images .. Canvases .. Check buttons and Radio buttons .. GUI Events .. Event examples .. 16417 GUI Programming Title bar .. Disabling things .. Getting the state of a widget .. Message boxes .. Destroying things .. Updating .. Dialogs .. Menu bars .. New windows .. with GUIs .. 17618 Further Graphical Python 2 vs Python 3 .. The Python Imaging Library .. Pygame .. 182 CONTENTSviiIII Intermediate Topics18319 Miscellaneous topics Mutability and References .. Tuples.

4 Sets .. Unicode .. with strings .. tips and tricks .. your Python programs on other computers .. 19620 Useful Importing modules .. Dates and times .. Working with files and directories .. Running and quitting programs .. Zip files .. Getting files from the internet .. Sound .. Your own modules .. 20621 Regular Introduction .. Syntax .. Summary .. Groups .. Other functions .. Examples .. 21622 Themathmodule .. Scientific notation .. Comparing floating point numbers .. Fractions .. Thedecimalmodule .. Complex numbers .. More with lists and arrays .. Random numbers .. Miscellaneous topics .. the Python shell as a calculator .. 22923 Working with First-class functions .. Anonymous functions .. Recursion .. ,filter,reduce, and list comprehensions .. Theoperatormodule.

5 More about function arguments .. 23524 Permutations and combinations .. Cartesian product .. Grouping things .. Miscellaneous things fromitertools.. Counting things .. 24225 Basics .. More with exceptions .. 247 Bibliography249 Index249 PrefaceMy goal here is for something that is partly a tutorial and partly a reference book. I like howtutorials get you up and running quickly, but they can often be a little wordy and books contain a lot of good information, but they are often too terse, and they don toften give you a sense of what is important. My aim here is for something in the spirit of a tutorialbut still useful as a reference. I summarize information in tables and give a lot of short exampleprograms. I also like to jump right into things and fill in background information as I go, ratherthan covering the background material book started out as about 30 pages of notes for students in my introductory Programming classat Mount St.

6 Mary s University. Most of these students have no prior Programming experience, andthat has affected my approach. I leave out a lot of technical details and sometimes I oversimplifythings. Some of these details are filled in later in the book, though other details are never filled this book is not designed to cover everything, and I recommend reading other books and thePython documentation to fill in the style of Programming in this book is geared towards the kinds of Programming things I like todo short programs, often of a mathematical nature, small utilities to make my life easier, and smallcomputer games. In fact, the things I cover in the book are the things that I have found most usefulor interesting in my Programming experience, and this book serves partly to document those thingsfor myself. This book is not designed as a thorough preparation for a career in software readers should progress from this book to a book that has more on computer science andthe design and organization of large terms of structuring a course around this book or learning on your own, the basis is most ofPart I.

7 The first four chapters are critically important. Chapter 5 is useful, but not all of it is 6 (strings) should be done before Chapter 7 (lists). Chapter 8 contains some more advancedlist topics. Much of this can be skipped, though it is all interesting and useful. In particular, thatchapter covers list comprehensions, which I use extensively later in the book. While you can getaway without using list comprehensions, they provide an elegant and efficient way of doing 9 (while loops) is important. Chapter 10 contains a bunch of miscellaneous topics, all ofwhich are useful, but many can be skipped if need be. The final four chapters of Part I are aboutdictionaries, text files, functions, and object-oriented II is about graphics, mostly GUI Programming with Tkinter. You can very quickly write somenice programs using Tkinter. For instance, Section presents a 20-line working (though notixxCONTENTS perfect) tic-tac-toe game.

8 The final chapter of Part II covers a bit about the Python Imaging III contains a lot of the fun and interesting things you can do with Python . If you are structur-ing a one-semester course around this book, you might want to pick a few topics in Part III to goover. This part of the book could also serve as a reference or as a place for interested and motivatedstudents to learn more. All of the topics in this part of the book are things that I have found usefulat one point or this book was designed to be used in an introductory Programming course, it is also usefulfor those with prior Programming experience looking to learn Python . If you are one of thosepeople, you should be able to breeze through the first several chapters. You should find Part II tobe a concise, but not superficial, treatment on GUI Programming . Part III contains information onthe features of Python that allow you to accomplish big things with surprisingly little preparing this book the Python documentation at was indispensable.

9 Thisbook was composed entirely in LATEX. There are a number of LATEX packages, particularlylistingsandhyperref, that were particulary helpful. LATEX code from helpedme get thelistingspackage to nicely highlight the Python for the longer programs as well as text files used in the text and exercises are available send comments, corrections, and suggestions updated August 19, IBasics1 Chapter 1 Getting StartedThis chapter will get you up and running with Python , from downloading it to writing Installing PythonGo to and download the latest version of Python (version as of this writing).It should be painless to install. If you have a Mac or Linux, you may already have Python on yourcomputer, though it may be an older version. If it is version or earlier, then you should installthe latest version, as many of the programs in this book will not work correctly on older IDLEIDLE is a simple integrated development environment (IDE) that comes with Python .

10 It s a pro-gram that allows you to type in your programs and run them. There are other IDEs for Python , butfor now I would suggest sticking with IDLE as it is simple to use. You can find IDLE in the folder on your you first start IDLE, it starts up in the shell, which is an interactive window where you cantype in Python code and see the output in the same window. I often use the shell in place of mycalculator or to try out small pieces of code. But most of the time you will want to open up a newwindow and type the program in least on Windows, if you click on a Python file on your desktop, your system will run theprogram, but not show the code, which is probably not what you want. Instead, if you right-clickon the file, there should be an option calledEdit with Idle. To edit an existing Python file,34 CHAPTER 1. GETTING STARTED either do that or start up IDLE and open the file through shortcutsThe following keystrokes work in IDLE and can really speed up your +CCopy selected textCTRL+XCut selected textCTRL+VPasteCTRL+ZUndo the last keystroke or group of keystrokesCTRL+SHIFT+ZRedo the last keystroke or group of keystrokesF5 Run A first programStart IDLE and open up a new window (chooseNew Windowunder theFileMenu).


Related search queries