Sign up
Log in
Home
Language tracks
Python track
Exercises
Exercises on the Python track
Join the Python Track
117 exercises to help you master Python
easy
Hello World
The classical introductory exercise. Just say "Hello, World!"
conditionals
optional values
text formatting
easy
Two Fer
Create a sentence of the form "One for X, one for me."
conditionals
optional values
text formatting
easy
Raindrops
Convert a number to a string, the content of which depends on the number's factors.
conditionals
integers
text formatting
easy
High Scores
Manage a player's High Score list
sequences
text formatting
classes
conditionals
easy
Matrix
Given a string representing a matrix of numbers, return the rows and columns of that matrix.
integers
loops
matrices
type conversion
easy
Hamming
Calculate the Hamming difference between two DNA strands.
algorithms
conditionals
filtering
logic
loops
sequences
sets
strings
easy
Isogram
Determine if a word or phrase is an isogram.
algorithms
conditionals
loops
strings
medium
Twelve Days
Output the lyrics to 'The Twelve Days of Christmas'
lists
strings
text formatting
easy
Word Count
Given a phrase, count the occurrences of each word in that phrase.
algorithms
logic
pattern recognition
strings
text formatting
easy
Scrabble Score
Given a word, compute the Scrabble score for that word.
games
loops
maps
strings
easy
Acronym
Convert a long phrase to its acronym
regular expressions
strings
easy
Kindergarten Garden
Given a diagram, determine which plants each child in the kindergarten class is responsible for.
arrays
classes
optional values
variables
easy
Grade School
Given students' names along with the grade that they are in, create a roster for the school
conditionals
filtering
integers
lists
sorting
strings
medium
Luhn
Given a number determine whether or not it is valid per the Luhn formula.
algorithms
conditionals
loops
pattern matching
security
medium
Clock
Implement a clock that handles times without dates.
classes
logic
text formatting
time
easy
Markdown
Refactor a Markdown parser
refactoring
text formatting
medium
Tournament
Tally the results of a small football competition.
conditionals
loops
maps
parsing
medium
Book Store
To try and encourage more sales of different books from a popular 5 book series, a bookshop has decided to offer discounts of multiple-book purchases.
lists
loops
recursion
easy
Leap
Given a year, report if it is a leap year.
booleans
conditionals
logic
hard
Rest API
Implement a RESTful API for tracking IOUs.
parsing
strings
easy
Reverse String
Reverse a string
strings
easy
Pangram
Determine if a sentence is a pangram.
algorithms
conditionals
filtering
logic
loops
strings
easy
RNA Transcription
Given a DNA strand, return its RNA Complement Transcription.
conditionals
logic
loops
maps
strings
transforming
easy
ISBN Verifier
Check if a given string is a valid ISBN-10 number.
conditionals
integers
parsing
strings
type conversion
easy
Gigasecond
Given a moment, determine the moment that would be after a gigasecond has passed.
dates
time
easy
Bob
Bob is a lackadaisical teenager. In conversation, his responses are very limited.
conditionals
equality
strings
easy
Yacht
Score a single throw of dice in the game Yacht
conditionals
equality
games
integers
pattern matching
sequences
easy
Run Length Encoding
Implement run-length encoding and decoding.
algorithms
strings
text formatting
easy
Meetup
Calculate the date of meetups.
conditionals
dates
parsing
pattern recognition
strings
easy
Armstrong Numbers
Determine if a number is an Armstrong number
algorithms
loops
math
easy
Rotational Cipher
Create an implementation of the rotational cipher, also sometimes called the Caesar cipher.
logic
loops
strings
easy
Difference Of Squares
Find the difference between the square of the sum and the sum of the squares of the first N natural numbers.
math
easy
Anagram
Given a word and a list of possible anagrams, select the correct sublist.
algorithms
logic
parsing
strings
easy
Allergies
Given a person's allergy score, determine whether or not they're allergic to a given item, and their full list of allergies.
bitwise operations
classes
enumerations
easy
Series
Given a string of digits, output all the contiguous substrings of length `n` in that string.
algorithms
arrays
conditionals
loops
easy
Robot Simulator
Write a robot simulator.
algorithms
classes
conditionals
loops
tuples
variables
easy
Sieve
Use the Sieve of Eratosthenes to find all the primes from 2 up to a given number.
algorithms
conditionals
lists
loops
math
easy
Atbash Cipher
Create an implementation of the atbash cipher, an ancient encryption system created in the Middle East.
algorithms
conditionals
loops
strings
easy
Sum Of Multiples
Given a number, find the sum of all the multiples of particular numbers up to but not including that number.
integers
math
easy
Say
Given a number from 0 to 999,999,999,999, spell out that number in English.
loops
parsing
text formatting
transforming
easy
Largest Series Product
Given a string of digits, calculate the largest product for a contiguous substring of digits of length n.
conditionals
logic
loops
math
easy
Flatten Array
Take a nested list and return a single list with all values except nil/null
algorithms
lists
recursion
transforming
easy
Roman Numerals
Write a function to convert from normal numbers to Roman Numerals.
conditionals
integers
logic
loops
strings
easy
Space Age
Given an age in seconds, calculate how old someone is in terms of a given planet's solar years.
conditionals
floating point numbers
integers
easy
Grains
Calculate the number of grains of wheat on a chessboard given that the number on each square doubles.
bitwise operations
integers
type conversion
easy
ETL
We are going to do the `Transform` step of an Extract-Transform-Load.
loops
maps
transforming
easy
Prime Factors
Compute the prime factors of a given natural number.
algorithms
logic
loops
math
easy
Pig Latin
Implement a program that translates from English to Pig Latin
conditionals
loops
regular expressions
strings
text formatting
easy
Simple Cipher
Implement a simple shift cipher like Caesar and a more secure substitution cipher
cryptography
strings
text formatting
easy
Crypto Square
Implement the classic method for composing secret messages called a square code.
strings
text formatting
transforming
easy
Sublist
Write a function to determine if a list is a sublist of another list.
lists
loops
searching
easy
Pythagorean Triplet
There exists exactly one Pythagorean triplet for which a + b + c = 1000. Find the product a * b * c.
algorithms
conditionals
enumerations
equality
filtering
lists
logic
loops
searching
sets
tuples
variables
math
easy
Circular Buffer
A data structure that uses a single, fixed-size buffer as if it were connected end-to-end.
algorithms
classes
conditionals
exception handling
queues
easy
Robot Name
Manage robot factory settings.
pattern matching
randomness
regular expressions
strings
text formatting
easy
Rail Fence Cipher
Implement encoding and decoding for the rail fence cipher.
algorithms
cryptography
lists
text formatting
easy
Nth Prime
Given a number n, determine what the nth prime is.
algorithms
lists
loops
math
easy
Saddle Points
Detect saddle points in a matrix.
algorithms
conditionals
lists
loops
matrices
sets
easy
Beer Song
Produce the lyrics to that beloved classic, that field-trip favorite: 99 Bottles of Beer on the Wall.
conditionals
loops
strings
easy
Perfect Numbers
Determine if a number is perfect, abundant, or deficient based on Nicomachus' (60 - 120 CE) classification scheme for natural numbers.
algorithms
logic
loops
math
easy
Secret Handshake
Given a decimal number, convert it to the appropriate sequence of events for a secret handshake.
bitwise operations
conditionals
integers
lists
logic
loops
transforming
easy
Palindrome Products
Detect palindrome products in a given range.
loops
math
easy
Matching Brackets
Make sure the brackets and braces all match.
parsing
recursion
stacks
strings
easy
Minesweeper
Add the numbers to a minesweeper board
games
lists
loops
parsing
transforming
easy
Queen Attack
Given the position of two queens on a chess board, indicate whether or not they are positioned so that they can attack each other.
arrays
exception handling
games
logic
matrices
easy
Wordy
Parse and evaluate simple math word problems returning the answer as an integer.
logic
parsing
pattern matching
regular expressions
transforming
type conversion
easy
Phone Number
Clean up user-entered phone numbers so that they can be sent SMS messages.
conditionals
pattern matching
regular expressions
strings
easy
OCR Numbers
Given a 3 x 4 grid of pipes, underscores, and spaces, determine which number is represented, or whether it is garbled.
lists
parsing
pattern recognition
easy
House
Output the nursery rhyme 'This is the House that Jack Built'.
pattern recognition
recursion
strings
text formatting
easy
Triangle
Determine if a triangle is equilateral, isosceles, or scalene.
classes
conditionals
object oriented programming
pattern matching
medium
DOT DSL
Write a Domain Specific Language similar to the Graphviz dot language
classes
domain specific languages
equality
graphs
lists
object oriented programming
test driven development
transforming
easy
Transpose
Take input text and output it transposed.
algorithms
strings
transforming
easy
Tree Building
Refactor a tree building algorithm.
maps
records
refactoring
sorting
trees
easy
Poker
Pick the best hand(s) from a list of poker hands.
conditionals
lists
loops
parsing
easy
Zebra Puzzle
Solve the zebra puzzle.
logic
easy
Rectangles
Count the rectangles in an ASCII diagram.
algorithms
logic
pattern recognition
easy
Binary Search
Implement a binary search algorithm.
algorithms
conditionals
lists
loops
searching
easy
List Ops
Implement basic list operations
callbacks
conditionals
filtering
functional programming
lists
loops
searching
variables
easy
Simple Linked List
Write a simple linked list implementation that uses Elements and a List
algorithms
conditionals
lists
easy
Linked List
Implement a doubly linked list
algorithms
conditionals
lists
medium
Rational Numbers
Implement rational numbers.
classes
equality
floating point numbers
math
easy
Diamond
Given a letter, print a diamond starting with 'A' with the supplied letter at the widest point.
lists
loops
strings
easy
Variable Length Quantity
Implement variable length quantity encoding and decoding.
algorithms
bitwise operations
transforming
medium
All Your Base
Convert a number, represented as a sequence of digits in one base, to any other base.
integers
transforming
math
medium
Grep
Search a file for lines matching a regular expression pattern. Return the line number and contents of each matching line.
files
searching
text formatting
medium
Bowling
Score a bowling game
classes
exception handling
logic
medium
Word Search
Create a program to solve a word search puzzle.
searching
strings
medium
Alphametics
Write a function to solve alphametics puzzles.
conditionals
logic
easy
Scale Generator
Generate musical scales, given a starting note and a set of intervals.
pattern matching
strings
easy
Protein Translation
Translate RNA sequences into proteins.
pattern matching
strings
medium
Change
Correctly determine change to be given using the least number of coins
algorithms
arrays
loops
easy
Connect
Compute the result for a game of Hex / Polygon
parsing
transforming
easy
Collatz Conjecture
Calculate the number of steps to reach 1 using the Collatz conjecture
loops
math
medium
Go Counting
Count the scored points on a Go board.
classes
control flow
parsing
tuples
medium
Complex Numbers
Implement complex numbers.
equality
tuples
math
medium
Diffie Hellman
Diffie-Hellman key exchange.
algorithms
math
medium
Two Bucket
Given two buckets of different size, demonstrate how to measure an exact number of liters.
algorithms
conditionals
control flow
loops
medium
Forth
Implement an evaluator for a very simple subset of Forth
parsing
stacks
medium
Food Chain
Generate the lyrics of the song 'I Know an Old Lady Who Swallowed a Fly'
algorithms
conditionals
loops
hard
Zipper
Creating a zipper for a binary tree.
recursion
searching
trees
easy
Error Handling
Implement various kinds of error handling and resource management
exception handling
medium
Dominoes
Make a chain of dominoes.
lists
tuples
hard
POV
Reparent a graph on a selected node
graphs
recursion
searching
trees
hard
React
Implement a basic reactive system.
callbacks
events
reactive programming
medium
Binary Search Tree
Insert and search for numbers in a binary tree.
classes
object oriented programming
recursion
searching
trees
medium
Hangman
Implement the logic of the hangman game using functional reactive programming.
strings
medium
Custom Set
Create a custom set type.
sets
easy
Spiral Matrix
Given the size, return a square matrix of numbers in spiral order.
algorithms
control flow
lists
medium
SGF Parsing
Parsing a Smart Game Format string.
parsing
trees
medium
Bank Account
Simulate a bank account supporting opening/closing, withdraws, and deposits of money. Watch out for concurrent transactions!
classes
concurrency
conditionals
medium
Ledger
Refactor a ledger printer.
globalization
refactoring
strings
medium
Affine Cipher
Create an implementation of the Affine cipher, an ancient encryption algorithm from the Middle East.
algorithms
cryptography
strings
easy
D&D Character
Randomly generate Dungeons & Dragons characters
randomness
integers
medium
Satellite
Rebuild binary trees from pre-order and in-order traversals.
pattern recognition
recursion
transforming
trees
easy
Darts
Write a function that returns the earned points in a single toss of a Darts game
conditionals
math
easy
Resistor Color
Convert a resistor band's color to its numeric representation
arrays
easy
Resistor Color Duo
Convert color codes, as used on resistors, to a numeric value.
arrays
medium
Knapsack
Given a knapsack that can only carry a certain weight, determine which items to put in the knapsack in order to maximize their combined value.
algorithms
lists
loops