Compound interest
Return the future balance after compound interest, rounded to two decimals.
Clamp a Number to a Range
Implement a clamp function that returns a value within a specified range.
Leap Year Checker
Implement a function that decides whether a year is a leap year according to the standard Gregorian rules.
Grade from Score
Write a function that maps a numeric score to its letter grade using standard grading thresholds.
Min of three numbers
Write a function that returns the minimum of three integers.
Integer division and remainder
Write a function that performs integer division and returns both quotient and remainder.
Count down from n
Implement a function that returns a list from n down to 1.
Sum numbers from 1 to n
Implement a function that computes the sum of all integers from 1 to n.
Sign of a Number
Write a function that returns the sign of a number as a string.
Is a multiple of both
Write a function that returns True if a number is divisible by both of two given divisors.
Boolean from comparison chain
Implement a function that evaluates a chain of comparisons and returns the boolean result.
Max of a variable-length list
Implement a function that returns the maximum value from a list of numbers without using max().
Classify triangle by sides
Write a function that classifies a triangle based on three side lengths.
Between inclusive
Write a function that returns True if a number is between two given bounds, inclusive of the bounds.
Last Occurrence of a Value
Implement a function that returns the last index of a given value in a list, or -1 if it's not present.
Cycle a List Once
Implement a function that rotates a list right by one position.
Boolean Mask Filter
Write a function that filters a list based on a boolean mask and returns the selected elements.
Replace negatives with zero
Implement a function that replaces all negative numbers in a list with zero.
Set symmetric difference
Write a function that returns the elements found in exactly one of two sets, sorted ascending.
Swap Two Values
Implement a Python function that swaps two given values and returns them in swapped order.
Hello, name!
Implement a function that returns a personalized greeting for a given name.
Leap Year Checker
Implement a function that returns True if a year is a leap year according to the Gregorian calendar rules.
Grade Calculator
Implement a function that converts a numeric score to a letter grade using a standard scale.
Minutes to Hours: Time Conversion Helper
Write a function that converts minutes into a human-readable 'Xh Ym' string, with special cases for zero and whole hours.
Simple Interest Calculator
Implement a function that calculates simple interest given principal, annual rate, and time in years.
Tip Calculator
Write a function that calculates the total bill after adding a given tip percentage.
Absolute Difference
Implement a function that returns the absolute difference between two numbers.
Max of three numbers
Implement a function that returns the maximum of three numbers using comparisons.
Sign of a number
Write a function sign_of_number that returns -1 for negatives, 0 for zero, and 1 for positives.
Countdown printer
Implement a function that prints a countdown from a given number down to 1, then returns 'Go!'.
Sum from 1 to n
Write a function that returns the sum of all integers from 1 to n (inclusive).
Average of a list
Write a function that computes the average of a list of numbers, handling empty lists by returning 0.
Find Minimum Value
Write a function that returns the minimum integer from a given list.
Is divisible by?
Create a function that returns True if a is divisible by b with no remainder, with a clear definition of edge cases.
Round to nearest ten
Write a function that rounds any integer to the nearest multiple of ten.
Fahrenheit to Celsius
Implement a function that converts degrees Fahrenheit to degrees Celsius.
Speed Converter
Write a function to convert speeds between kilometers per hour and meters per second.
Area of Rectangle
Write a function that returns the area of a rectangle given its width and height.
Circle Circumference Calculator
Implement a function that computes the circumference of a circle from its radius using the formula 2πr.
Volume of Cube
Write a Python function that returns the volume of a cube given its side length.
Modulo Remainder
Implement a function that returns the remainder of a divided by b without using the modulo operator.
Print Pyramid Pattern
Implement a function that returns a centered asterisk pyramid as a list of strings.
Last Digit Extractor
Write a function that returns the last digit of a non-negative integer using the modulo operator.
Count word occurrences
Write a function that takes a sentence and returns a dictionary of word counts.
Map, Filter, Reduce
Implement three functions using map, filter, and reduce to manipulate a list of integers.
Variadic Sum Function
Implement a variadic function that sums an arbitrary number of numeric arguments.
Linear Search Implementation
Implement a linear search function that returns the index of the first occurrence of a target in a list, or -1 if not found.
Garbage Collection Hint
Write a function that predicts when an object is garbage collected based on reference counting.
Enumerate with start
Implement a function that mimics Python's enumerate with a custom start index.
Palindromic Number Check
Write a function to check if a given integer is a palindrome.
Hexagonal Number
Write a function to check if a positive integer is a hexagonal number.
Count trailing zeros
Write a function that counts the number of trailing zeros in the decimal representation of a positive integer.
Count Leading Zeros
Write a function that returns the number of leading zeros in a list of integers.
Strip and Collapse Whitespace
Write a function that strips leading/trailing whitespace and collapses inner runs of whitespace to single spaces.
Snake case to camel case
Implement a function that converts snake_case strings to camelCase.
Camel case to snake case
Write a function that converts camelCase input to snake_case while handling acronyms and numbers correctly.
Remove punctuation
Write a function that removes all ASCII punctuation characters from a string.
Is pangram
Write a function that determines whether a given string is a pangram, ignoring case and non-letter characters.
Caesar Cipher Shift
Implement a function to apply a Caesar cipher shift to a string, preserving case and ignoring non-letters.
Longest word in a sentence
Write a function that returns the longest word from a sentence, with first-occurrence tie-breaking.
Replace vowels with stars
Write a function that replaces every vowel in a given string with an asterisk.
Is isogram
Implement a function that determines whether a string is an isogram (no repeated letters, case-insensitive).
Kebab Case a Phrase
Implement a function that converts a phrase into lowercase kebab-case, handling spaces, punctuation, and camelCase.
Find all indexes of a substring
Write a function that returns a list of all starting indexes where a substring appears in a string, including overlapping occurrences.
Remove Consecutive Duplicate Letters
Implement a function that removes consecutive duplicate letters from a string, keeping only one occurrence of each run.
Is rotation of another string
Write a function to determine if one string is a rotation of another string.
Count words in a sentence
Implement a function to count words in a sentence, ignoring extra whitespace and handling empty strings.
Center a string in a width
Write a function that centers a string within a specified width by adding spaces on both sides.
Caesar Cipher Shift
Write a function that shifts letters in a string by a given amount, preserving case and ignoring non-letters.
Count consonants
Write a function that counts the number of consonant letters in a string.
Longest Word Finder
Write a function that extracts alphabetic words from a string and returns the longest one, with ties broken by earliest position.
Abbreviate Name
Create a function that takes a full name and returns an abbreviated version with initials and the last name.
Extract digits from string
Write a function that extracts all digit characters from a given string, preserving their original order.
Replace Spaces with Dashes
Write a function that replaces every space in a string with a dash.
Capitalize First Letter
Write a function that capitalizes the first letter of each word in a string.
Snake case converter
Implement a function that converts a string to snake_case according to given rules.
Camel Case Converter
Write a function that converts a space-separated phrase into lower camelCase.
Kebab Case Converter
Implement a function that converts any string to kebab-case, handling spaces, underscores, camelCase, and punctuation.
Is isogram?
Write a function that checks whether a given word is an isogram, ignoring letter case and only considering alphabetic characters.
Rotate String Right
Implement a function that rotates a given string to the right by a specified number of positions, handling shifts larger than the string length.
Compress Consecutive Chars
Write a function that compresses a string by replacing runs of identical characters with the character followed by the count.
Expand compressed string
Implement a function that expands run-length encoded strings (e.g., 'a3b2' → 'aaabb').
Find substring index
Implement a function that returns the starting index of the first occurrence of a substring using only basic string indexing and slicing.
Count Substrings
Implement a function that counts non-overlapping occurrences of a substring in a given string.
Sort characters in string
Write a function that sorts the characters in a string and returns the sorted string.
Index of First Occurrence
Implement a function that finds the starting index of a substring within a string, returning -1 when absent.
Error message formatter
Write a function that constructs a formatted error message from a code, an optional context, and a fallback message.
Stack Trace Sanitizer
Implement a function that rewrites traceback file paths to basenames only.
Parse Log Line
Write a function that parses a log line and returns a dictionary with timestamp, level, and message.
Replace multiple spaces
Implement a function that replaces every sequence of spaces with a single space.
Extract Quoted Strings
Write a function that extracts the text inside every double-quoted substring from a given string.
Normalize Whitespace
Write a function that normalizes any whitespace in a string to single spaces and trims the ends.
Strip Leading Zeros
Write a function that strips leading zeros from a string representing a non-negative integer.
Find all numbers in text
Write a function that extracts all standalone integers from a text string using regular expressions.
Extract file extensions
Implement a function that extracts the extension from a filename according to standard rules.
Validate username format
Implement a function that validates a username according to length, allowed characters, and no consecutive underscores.
Replace template variables
Implement a function that replaces {{variable}} placeholders in a string using a dictionary, leaving unknown placeholders intact.
Hamming Distance
Implement a function that computes the Hamming distance between two strings of equal length.
Chunk a list into n-sized parts
Write a function that divides a list into sublists of at most n elements.
Rotate Left by k
Implement a function that rotates a list left by k positions.
Interleave Two Lists
Write a function that interleaves two lists element by element, preserving order.
Running Maximum
Implement a function that returns a list where each element is the largest value seen so far.
Insert into a Sorted List
Implement a function that inserts a value into a sorted list at the correct position using binary search.
Zip lists into pairs
Write a function that takes two lists and returns a list of two-element sublists pairing elements by index up to the shortest length.
Middle Element of an Odd-Length List
Implement a function that returns the middle element of an odd-length list.
Is Subset of Another List
Write a function that returns True if every element in a given list exists in another list, ignoring duplicates.
Unzip pairs into two lists
Write a function that takes a list of pairs and returns two separate lists: first elements and second elements.
Generate a Multiplication Table
Build a function that returns an n x n multiplication table as a list of lists.
Majority Element Finder
Implement a function that returns the majority element in a list, which appears more than half the time.
Union of Two Lists
Implement a function that combines two lists and returns only unique elements.
Difference of Two Lists
Write a function that returns items in list a that are not in list b, preserving order and duplicates.
Chunk list into groups
Implement a function that splits a list into sublists of a given size.
Zip Two Lists
Write a function that pairs elements from two lists by index, stopping at the shorter list.
Rearrange Positives and Negatives
Write a function that rearranges a list in-place so all negative numbers come before non-negative numbers.
Last occurrence index
Implement a function that returns the last index of a given value in a list, or -1 if the value is not present.
Merge dicts summing values
Write a function that merges two dictionaries by summing values for duplicated keys.
Are two lists the same multiset
Write a function that checks if two lists contain the same elements with the same multiplicities, ignoring order.
Word to Index Map
Create a function that returns a dictionary mapping each unique word to the index of its first occurrence.
Missing keys default zero
Write a function to sum numeric values from dictionaries, treating missing keys as zero.
Nested get with dotted path
Implement a function that safely retrieves a value from a deeply nested dictionary using a dot-separated path, returning a default if any key is missing.
Common Keys of Two Dictionaries
Implement a function that finds keys shared by two dictionaries and returns them sorted.
Union of Many Sets
Implement a function that takes any number of sets and returns a sorted list of their union.
Mode of a list via counting
Implement a function that returns the mode of a list, resolving ties by the element that appears first.
Replace keys with a mapping
Write a function that renames keys in a dictionary according to a mapping, with duplicate handling.
Symmetric Difference
Write a function that computes the symmetric difference of two lists, returning a sorted list of unique elements.
Subset of another set
Write a function that checks if every element of one set is contained in another.
Frequency sort descending
Write a function that sorts a list by frequency descending while preserving original order for ties.
Count Pairs with Sum
Implement a function that counts the number of distinct pairs in a list summing to a target.
Bind First Argument
Implement bind_first_arg, a decorator that fixes the first argument of any function.
Event emitter basics
Implement an EventEmitter class with subscribe/emit/unsubscribe functionality.
Index of peak element
Implement a function that returns the index of any peak element in a given integer array.
Generator Pipeline
Implement a generator function that yields only even numbers from an input list, squared.
Fibonacci Generator
Create a generator function that yields Fibonacci numbers from 0 upward until a given limit.
Pairwise Sequence Pairs
Write a generator function pairwise that yields each consecutive overlapping pair from any iterable as lists.
Groupby Consecutive
Write a generator function that yields (value, list_of_occurrences) for each run of consecutive equal items.
Collatz Generator
Implement a generator function that yields the Collatz sequence starting from a given positive integer.
File Line Reader Generator
Implement a generator function that reads a file-like object and yields each non-empty line without loading the whole file into memory.
Tree inorder generator
Write a generator function that yields a binary tree's node values in inorder traversal.
Once Decorator: Run a Function Only Once
Implement a decorator that caches and returns the result of the first call for subsequent calls.
Timing Decorator
Implement a decorator that prints the execution time of a function.
Print Args Decorator
Write a decorator that prints function name and arguments, then returns the original result.
Safe divide function
Implement safe_divide that returns None on ZeroDivisionError and TypeError.
Safe Float Parser
Write a function that safely converts a string to a float, returning None for invalid inputs.
Divide with zero check
Write a function that safely divides two numbers, catching division by zero.
Key error handler
Implement a safe dictionary access function that returns a default value on missing keys.
Else on try block
Implement a function that uses try-except-else to safely divide two numbers and return a result or error description.
Validate phone number
Write a function that uses regular expressions to determine if a given string is a valid US phone number.
Match IPv4 Address
Write a function that uses a regular expression to check if a string is a valid IPv4 address.
Validate Hex Color Code
Write a function that validates hex color codes using regular expressions.
Lookahead Validation
Write a regex-based function to check if a password meets length and character class requirements.
Nth Triangular Number
Implement a function that returns the nth triangular number efficiently.
Integer Square Root Floor
Implement a function that returns the greatest integer whose square is ≤ n, using only integer operations.
Catalan number
Implement a function that returns the nth Catalan number using dynamic programming.
Stirling number
Implement a function to compute Stirling numbers of the second kind S(n,k).
Euler Totient Function
Implement Euler's totient function φ(n) for positive integers.
Perfect Number Check
Write a function that returns True if a number is perfect, i.e., equal to the sum of its proper divisors.
Abundant Number Check
Implement a function to check whether a given integer is abundant: sum of proper divisors exceeds the number.
Amicable Numbers Check
Write a function that checks if two numbers are an amicable pair by comparing sums of proper divisors.
Armstrong Number Check
Implement a function that checks if a given integer is an Armstrong number.
Happy number check
Implement a function that returns True if a number is happy, False otherwise.
Harshad Number Check
Write a function that checks if a number is a Harshad (or Niven) number.
Triangular Number
Implement a function that returns the nth triangular number using the closed-form formula.
Lucas Sequence
Implement a function to compute the n-th Lucas number using iteration or recursion with memoization.
Partition function
Write a function that returns the number of ways to write a positive integer as a sum of positive integers (order irrelevant).
Multiply without multiply
Write a function that multiplies two integers using only addition, subtraction, and bit shifts — no * operator.
Count Set Bits
Implement a function that returns the number of set bits (1s) in the binary representation of a non-negative integer.
Gray Code Encode
Implement a function that converts a non-negative integer to its Gray code representation using bitwise XOR and shift.
Find Rightmost Set Bit
Implement a function that returns the 1-indexed position of the rightmost set bit of a positive integer, or 0 if none.
Rotate Bits Left
Implement a function that rotates the bits of an integer to the left by a specified number of positions.
Add without plus
Implement a function that adds two integers using only bitwise operations, no arithmetic plus or minus.
Set kth Bit
Implement a function that sets the kth bit (0-indexed) of a non-negative integer to 1 and returns the result.
Clear kth Bit
Implement a function that clears the k-th bit of a non-negative integer (turns it to 0) using bitwise operations.
Compress Bits Run
Write a function that compresses a binary string by representing consecutive identical bits as a count-bit pair.
Brian Kernighan count
Implement a function that counts set bits using Brian Kernighan's efficient algorithm.
Climbing Stairs
Implement a function that returns the number of distinct ways to climb n stairs using steps of 1 or 2.
Binary Tree Inorder Traversal
Implement an inorder traversal function that returns node values in left-root-right order.
Preorder Traversal
Implement a function that returns the preorder traversal values of a binary tree.
Postorder Traversal
Implement a function that returns the postorder traversal of a binary tree as a list of node values.
Symmetric Tree Check
Write a function that checks whether a binary tree is symmetric (a mirror of itself).
Same Tree Check
Write a function that checks whether two binary trees are identical in structure and node values.
Cycle Detection in Undirected Graph
Write a function that detects if an undirected graph contains a cycle.
Find center of star graph
Write a function that finds the center node of a star graph from its list of edges in O(1) time.
Wildcard Match (Simple)
Write a function that checks whether a string matches a pattern with '*' and '?' wildcards.
Permutation Generator
Write a function that returns all permutations of a list of distinct integers.
Longest Substring Without Repeating Characters
Implement a function that returns the length of the longest substring without repeating characters.
Days in month
Write a function that returns the number of days in a given month and year, correctly handling leap years.
Showing 186 challenges · easy
Guide: free Python coding challenges
Practice Python by solving problems
PythonSkillset challenges are hands-on coding exercises from beginner to advanced. Open a challenge, read the problem, write Python in the split-pane editor, and run tests with Pyodide — no install required.
How to use the arena
- Pick a category — basics, algorithms, strings, and more
- Open a challenge, read the statement, and edit the starter code
- Run tests, fix failures, then try a related quiz or tutorial lesson
Challenges vs tutorials and quizzes
Challenges test what you can build under constraints. For guided teaching, use our Python tutorials. For quick checks, try quizzes or copy snippets from code samples.