Tiny python projects pdf

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

Code for Tiny Python Projects (Manning, 2020, ISBN 1617297518). Learning Python through test-driven development of games and puzzles.

License

kyclark/tiny_python_projects

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

This is the code repository for the Manning Publications book, Tiny Python Projects, by Ken Youens-Clark:

There is a directory for each chapter of the book. Each directory contains a test.py program you can use with pytest to check that you have written the program correctly. I have included a short README to describe each exercise. If you have problems writing code (or if you would like to support this project!), the book contains details about the skills you need.

The testing step is integral to writing and solving these challenges as well as to the methodology of the book. I advocate a «test-driven development» mentality where we write tests before we write code. The tests should define what it means for a program to be correct, and then we write programs to satisfy the tests. In this project, I’ve written all the tests for you, but I also encourage you to write your own functions and tests. You should run the test suite after every change to your program to ensure you are making progress!

I’ve been making videos for each chapter on my YouTube channel:

Here are the videos I’ve completed so far:

  • Chapter 1: How to write and test a Python program: How to create a Python program, understanding comments and the shebang, how to make a program executable and install into your $PATH, how to write a main() function, add docstrings, format your code, and run tests.
  • Chapter 2: Crow’s Nest: How to write a Python program that accepts a single, positional argument and creates a newly formatted output string.
  • Chapter 3: Picnic: Writing a Python program that accepts multiple string arguments and formats the results depending on the number of items.
  • Chapter 4: Jump The Five: Writing a Python program to encode the numerals in a given text using an algorithm called «Jump The Five.» Use of a dictionary as a lookup table, characters not in the dictionary remain unchanged. Introduction to encoding/decoding text, basic idea of encryption.
  • Chapter 5: Howler: Writing a Python program that can process input text either from the command line or from a file.The output prints either to STDOUT or to a file. Learning about «os.path.isfile», how to «open» a file handle for reading/writing, how to read/write the contents of a file.
  • Chapter 6: Word Count: Writing a Python program to emulate the wc (word count) program. Validates and processes multiple file inputs as well as STDIN and creates output of the counts of lines, words, and bytes for each file optionally with a «total» if more than one file is provided.
  • Chapter 7: Gashlycrumb: Writing a Python program that processes an input file to build a lookup table (dictionary) that is used with multiple positional arguments to translate to the values from the file.
  • Chapter 8: Apples and Bananas: Writing a Python program to find and replace elements in a string. Exploring multiple ways to write the same idea from for loops to list comprehensions to higher-order functions like map().
  • Chapter 9: Abuse: Writing a Python program to generate Shakespearean insults by randomly combining some number of adjectives with a randomly chosen noun. Learning about randomness, seeds, testing, how to use triple-quoted strings.
  • Chapter 10: Telephone: Using probabalistic and deterministc approaches to randomly mutating a string.
  • Chapter 11: Bottles of Beer: Writing a Python program to produce the verse to the «99 Bottles of Beer» song from a given starting point. Learning to count down, format strings, algorithm design. A focus on writing a function and unit test, exploring ways to incorporate our function to generate the verses from for loops to list comprehensions to map().
  • Chapter 12: Ransom: Writing a Python program that will randomly capitalize letters in a given piece of text for the nefarious purpose of creating a ransom note. Exploration of for loops, list comprehensions, and the map() function.
  • Chapter 13: Twelve Days of Christmas: Writing a Python program to create the verses for «The Twelve Days of Christmas» from a given day. Learning how to write a function and the test for it, then using the function in a list comprehension and a map to generate the output.
  • Chapter 14: The Rhymer: Writing a Python program that can split off any initial consonants from a word and append a list of prefixes to create new rhyming «words.» Exploration of regular expressions to handle words with no initial consonants, with one or more leading consonants, and nothing but consonants. Writing a stemmer() function and the test_stemmer() function to understand it. Using list comprehensions with guard statements and how that relates to the filter() function.
  • Chapter 15: The Kentucky Friar: In this chapter we delve further into regular expressions, first learning how to split a string using a regex so we can separate things that look like «words» from non-words like punctuation and whitespace. Then we try to identify the word «you» (case-insensitive) to turn into «y’all» and any 2-syllable words ending in «-ing» so we can replace the final «g» with an apostrophe so that «cooking» becomes «cookin'» but «swing» would remain «swing.» We then apply this to an entire body of text to Kentucky fry the words with amusing results.
  • Chapter 16: The Scrambler: Writing a Python program to find each «word» in a body of text and then scramble the letters such that the first and last letters remain in place, then reconstructing the text for output. Using regular expressions to split text, using random.shuffle() and understanding in-place mutation vs returning a new value. Comparing for loops to list comprehensions and the «map()» function.
  • Chapter 17: Mad Libs: Writing a Python program to play the classic Mad Libs game. Reading an input file with placeholders for parts of speech like «adjective» or «noun.» Getting the inputs to replace those from the user interactively via the «input()» function or taking them from the command-line arguments. Using regular expressions to find and replace the placeholders. Learning about greedy regex and how to make them not greedy. Using the re.findall() and re.sub() functions. Using sys.exit() to prematurely exit a program with an error message/value.
Читайте также:  Html files to wordpress

First use the GitHub interface to «fork» this repository into your own account. Then do git clone of your repository to get a local copy. Inside that checkout, do:

git remote add upstream https://github.com/kyclark/tiny_python_projects.git 

This will allow you to git pull upstream master in order to get updates. When you create new files, git add/commit/push them to your repository. (Please do not create pull requests on my repository — unless, of course, you have suggestions for improving my repo!).

About

Code for Tiny Python Projects (Manning, 2020, ISBN 1617297518). Learning Python through test-driven development of games and puzzles.

Источник

Tiny Python Projects

After you read this book and write all the programs, I would hope that you will be a zealot for creating programs that are documented, tested, and reproducible.

I think my ideal reader is someone who’s been trying to learn to code well but isn’t quite sure how to level up. Perhaps you are someone who’s been playing with Python or some other language that has a similar syntax, like Java(Script) or Perl. Maybe you’ve cut your teeth on something really different, like Haskell or Scheme, and you’re wondering how to translate your ideas to Python. Maybe you’ve been writing Python for a while and are looking for interesting challenges with enough structure to help you know when you’re moving in the right direction.

This is a book that will teach you to write well-structured, documented, testable code in Python. The material introduces best practices from industry such as testdriven development—that’s when the tests for a program exist even before the program itself is written! I will show you how to read documentation and Python Enhancement Proposals (PEPs) and how to write idiomatic code that other Python programmers would immediately recognize and understand.

Читайте также:  Html header margin bottom

This is probably not an ideal book for the absolute beginning programmer. I assume no prior knowledge of the Python language specifically, because I’m thinking of someone who is coming from another language. If you’ve never written a program in any language at all, you might do well to come back to this material when you are comfortable with ideas like variables, loops, and functions.

Исходный код: Перейти

Если вам понравилась эта книга поделитесь ею с друзьями, тем самым вы помогаете нам развиваться и добавлять всё больше интересных и нужным вам книг!

Источник

Tiny Python Projects

Tiny Python Projects

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 22 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.

Who says learning to program has to be boring? The 21 activities in this book teach Python fundamentals through puzzles and games. Not only will you be entertained with every exercise, but you’ll learn about text manipulation, basic algorithms, and lists and dictionaries as you go. It’s the ideal way for any Python newbie to gain confidence and experience.

  • Write command-line Python programs
  • Manipulate Python data structures
  • Use and control randomness
  • Write and run tests for programs and functions
  • Download testing suites for each project
Читайте также:  @font-face

The projects are tiny, but the rewards are big: each chapter in Tiny Python Projects challenges you with a new Python program, including a password creator, a word rhymer, and a Shakespearean insult generator. As you complete these entertaining exercises, you’ll graduate from a Python beginner to a confident programmer and you’ll have a good time doing it!

Источник

Tiny Python Projects

Tiny Python Projects

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 22 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.

Who says learning to program has to be boring? The 21 activities in this book teach Python fundamentals through puzzles and games. Not only will you be entertained with every exercise, but you’ll learn about text manipulation, basic algorithms, and lists and dictionaries as you go. It’s the ideal way for any Python newbie to gain confidence and experience.

  • Write command-line Python programs
  • Manipulate Python data structures
  • Use and control randomness
  • Write and run tests for programs and functions
  • Download testing suites for each project

The projects are tiny, but the rewards are big: each chapter in Tiny Python Projects challenges you with a new Python program, including a password creator, a word rhymer, and a Shakespearean insult generator. As you complete these entertaining exercises, you’ll graduate from a Python beginner to a confident programmer and you’ll have a good time doing it!

Источник

Оцените статью