Welcome to Manning India!

We are pleased to be able to offer regional eBook pricing for Indian residents.
All eBook prices are discounted 40% or more!
Tiny Python Projects
Learn coding and testing with puzzles and games
Ken Youens-Clark
  • MEAP began January 2020
  • Publication in Summer 2020 (estimated)
  • ISBN 9781617297519
  • 325 pages (estimated)
  • printed in black & white

Learn Python, one laugh at a time. No seriously, if you want to learn Python the way your next employer would expect you to, but don't want to get bored in the process, and learn really really quickly, read this!

Mafinar Khan
A long journey is really a lot of little steps. The same is true when you’re learning Python, so you may as well have some fun along the way! Written in a lighthearted style with entertaining exercises that build powerful skills, Tiny Python Projects takes you from amateur to Pythonista as you create 19 bitesize programs. Each tiny project teaches you a new programming concept, from the basics of lists and strings right through to regular expressions and randomness. Along the way you’ll also discover how testing can make you a better programmer in any language.
Table of Contents detailed table of contents

Introduction

Why Write Python?

Who Am I?

Who Are You?

Why Did I Write This Book?

Using test-driven development

Suggestions for writing

Setting up your environment

The command line and the Python REPL

Code formatting and linting

Getting the code

Starting new programs with new.py or template.py

Why Not Notebooks?

A Note about the lingo

1 How to write and test a Python program

1.1 How to write the world’s best "Hello, World!"

1.1.1 Comment lines

1.1.2 The shebang

1.1.3 Making a program executable

1.1.4 String diagrams

1.1.5 Adding a parameter

1.1.6 Writing and testing functions

1.1.7 Adding a main function

1.1.8 Why is testing important?

1.1.9 Adding type hints

1.1.10 Verification with mypy

1.1.11 Manually validating and documenting arguments

1.1.12 Documenting and validating arguments using argparse

1.1.13 Adding get_args

1.1.14 Checking style and errors

1.1.15 Making the argument optional

1.1.16 Testing hello.py

1.1.17 Starting a new program with new.py

1.2 Summary

2 Using argparse

2.1 Types of arguments

2.2 Using argparse

2.2.1 Creating the parser

2.2.2 A positional parameter

2.2.3 An optional string parameter

2.2.4 An optional numeric parameter

2.2.5 An optional file parameter

2.2.6 A flag

2.2.7 Returning from get_args

2.2.8 Manually checking arguments

2.3 Examples using argparse

2.3.1 Two different positional arguments

2.3.2 Two of the same positional arguments

2.3.3 One or more of the same positional arguments

2.3.4 Restricting values using choices

2.3.5 File arguments

2.3.6 Automatic help

2.4 Summary

3 The Crow’s Nest: Working with strings

3.1 Getting started

3.1.1 How to use the tests

3.1.2 Creating programs with new.py

3.1.3 Defining your arguments

3.1.4 Concatenating strings

3.1.5 Variable types

3.1.6 Getting just part of a string

3.1.7 Finding help in the REPL

3.1.8 String methods

3.1.9 String comparisons

3.1.10 Conditional branching

3.1.11 String formatting

3.2 Solution

3.3 Discussion

3.3.1 Defining the arguments with get_args

3.3.2 The main thing

3.3.3 Classifying the first character of a word

3.3.4 Printing the results

3.3.5 Running the test suite

3.3.6 Passing Tests

3.4 Summary

3.5 Going Further

4 Going on a picnic: Working with lists

4.1 Starting the program

4.2 Writing picnic.py

4.3 Stuff about lists

4.3.1 Adding one element to a list

4.3.2 Adding many elements to a list

4.3.3 Indexing lists

4.3.4 Slicing lists

4.3.5 Finding elements in a list

4.3.6 Removing elements from a list

4.3.7 Sorting and reversing a list

4.3.8 Lists are mutable

4.3.9 Joining a list

4.4 Conditional branching with if/elif/else

4.5 Solution

4.6 Discussion

4.6.1 Defining the arguments

4.6.2 Assigning and sorting the items

4.6.3 Formatting the items

4.6.4 Printing the items

4.6.5 Testing

4.7 Summary

4.8 Going Further

5 Jump the Five: Working with dictionaries

5.1 Dictionaries

5.1.1 Creating a dictionary

5.1.2 Accessing dictionary values

5.1.3 Other dictionary methods

5.2 Writing jump.py

5.3 Solution

5.4 Discussion

5.4.1 Defining the arguments

5.4.2 Using a dict for encoding

5.4.3 Method 1: Using a for loop to print each character

5.4.4 Method 2: Using a for loop to build a new string

5.4.5 Method 3: Using a for loop to build a new list

5.4.6 Method 4: List comprehension

5.4.7 Method 5: str.translate

5.4.8 (Not) using str.replace

5.5 Summary

5.6 Going Further

6 Howler: Working with files and STDOUT

6.1 Reading files

6.2 Writing files

6.3 Writing howler.py

6.4 Solution

6.5 Discussion

6.5.1 Defining the arguments

6.5.2 Reading input from a file or the command line

6.5.3 Choosing the output file handle

6.5.4 Printing the output

6.5.5 A low-memory version

6.6 Review

6.7 Going Further

7 Words Count: Reading files/STDIN, iterating lists, formatting strings

7.1 Writing wc.py

7.1.1 Defining file inputs

7.1.2 Iterating lists

7.1.3 What you’re counting

7.1.4 Formatting your results

7.2 Solution

7.3 Discussion

7.3.1 Defining the arguments

7.3.2 Reading a file using a for loop

7.4 Review

7.5 Going Further

8 Gashlycrumb: Looking items up in a dictionary

8.1 Writing gashlycrumb.py

8.2 Solution

8.3 Discussion

8.3.1 Handling the arguments

8.3.2 Reading the input file

8.3.3 Looping with for versus a list comprehensions

8.3.4 Dictionary lookups

8.4 Review

8.5 Going Further

9 Apples and Bananas: Find and replace

10 Dial-A-Curse: Generating random insults from lists of words

11 Telephone: Randomly mutating strings

12 Bottles of Beer Song: Writing and testing functions

13 Ransom: Randomly captalizing text

14 Twelve Days of Christmas: Algorithm design

15 Rhymer: Using regular expressions to create rhyming words

16 The Kentucky Friar: More regular expressions

17 The Scrambler: Randomly reordering the middles of words

18 Mad Libs: Using regular expressions

19 Gematria: Numeric encoding of text using ASCII values

20 Workout Of the Day (Parsing CSV file, creating text table output)

21 Password Strength

Appendixes

Appendix A: Setting up your development environment

About the Technology

Simple yet powerful, Python is one of the world’s most popular programming languages. You can use Python to write everything from simple utility programs to complex web applications and deep learning models. Whether you’re a researcher, a marketer, a data scientist, or a professional developer, Python is a fantastic skill to have in your toolbox.

About the book

Tiny Python Projects teaches you the big ideas of Python programming through small puzzles, tasks, and games. Each chapter challenges you with a fun new Python program for you to write and run, including a Shakespearean insult generator, an unbreakable password creator, and various text encoders. As you practice core Python language features and coding skills, you’ll also explore the principles of test-driven development by running your programs against a suite of specially designed tests. Designed for reading cover to cover or just dipping into the chapters that interest you, this entertaining book will have you parsing command-line arguments, getting interactive user input, and understanding many other programming techniques that scale easily from tiny Python projects to big ones!

What's inside

  • Write command-line Python programs
  • Process a variety of command-line arguments, options, and flags
  • Write and run tests for programs and functions
  • Manipulate Python data structures including strings, lists, tuples, and dictionaries
  • Use list and dictionary comprehensions and higher-order functions like map and filter
  • Write and use regular expressions
  • Use and control of randomness
  • Downloadable testing suites for each project

About the reader

For beginner Python programmers.

About the author

Ken Youens-Clark works at the University of Arizona as a Senior Scientific Programmer. He has an MS in Biosystems Engineering and has been programming for over 20 years.

Manning Early Access Program (MEAP) Read chapters as they are written, get the finished eBook as soon as it’s ready, and receive the pBook long before it's in bookstores.
MEAP combo $39.99 pBook + eBook + liveBook
MEAP eBook $31.99 pdf + ePub + kindle + liveBook
Prices displayed in rupees will be charged in USD when you check out.

placing your order...

Don't refresh or navigate away from the page.

FREE domestic shipping on three or more pBooks