Practice Arena

Python Coding Challenges

Write real Python in the browser. Instant feedback. From beginner to expert.

467 challenges 330 easy 120 medium 17 hard
Python Basics easy

FizzBuzz, precisely

Return a newline-separated string for 1..n: Fizz, Buzz, FizzBuzz, or the number.

control flow strings modulo
2
+10 pts 12m
Python Basics easy

Even or odd?

Return 'even' or 'odd' for an integer.

modulo conditionals
1
+5 pts 5m
Python Basics easy

Sum of digits

Return the sum of all decimal digits of a non-negative integer.

arithmetic loops
2
+8 pts 10m
Python Basics easy

Power of two?

Return True if n is an exact power of 2.

bitwise math
+8 pts 8m
Python Basics easy

Prime checker

Return True if n is a prime number.

math loops
1
+10 pts 10m
Python Basics easy

Compound interest

Return the future balance after compound interest, rounded to two decimals.

math functions finance
+12 pts 12m
Python Basics easy

Clamp a Number to a Range

Implement a clamp function that returns a value within a specified range.

numbers conditionals comparisons
+5 pts 5m
Python Basics easy

Min of three numbers

Write a function that returns the minimum of three integers.

min comparison function
+5 pts 5m
Python Basics easy

Integer division and remainder

Write a function that performs integer division and returns both quotient and remainder.

operators division remainder
+8 pts 10m
Python Basics easy

Count down from n

Implement a function that returns a list from n down to 1.

loops range lists
+5 pts 5m
Python Basics easy

Multiplication Table Row

Return the nth row of a multiplication table as a list of 1..n products.

loops lists multiplication
+5 pts 5m
Python Basics easy

Sign of a Number

Write a function that returns the sign of a number as a string.

conditionals numbers comparison
+5 pts 5m
Python Basics easy

Is a multiple of both

Write a function that returns True if a number is divisible by both of two given divisors.

modulo boolean function
+5 pts 5m
Python Basics easy

Digit count of an integer

Given an integer, return the number of digits it has, handling negatives and zero correctly.

integers loops arithmetic
+5 pts 5m
Python Basics easy

Boolean from comparison chain

Implement a function that evaluates a chain of comparisons and returns the boolean result.

comparison booleans evaluation
+8 pts 10m
Python Basics easy

Max of a variable-length list

Implement a function that returns the maximum value from a list of numbers without using max().

conditionals loops comparison
+10 pts 10m
Python Basics easy

Toggle a boolean n times

Apply boolean toggling n times and return the final boolean value.

booleans arithmetic modulo
+6 pts 8m
Python Basics easy

Between inclusive

Write a function that returns True if a number is between two given bounds, inclusive of the bounds.

comparison conditionals boundaries
+8 pts 10m
Python Basics easy

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.

lists search indexing
+10 pts 15m
Python Basics easy

Boolean Mask Filter

Write a function that filters a list based on a boolean mask and returns the selected elements.

filter boolean lists
+10 pts 15m
Python Basics easy

Set symmetric difference

Write a function that returns the elements found in exactly one of two sets, sorted ascending.

sets symmetric-difference sorting
+10 pts 15m
Python Basics easy

Swap Two Values

Implement a Python function that swaps two given values and returns them in swapped order.

variables assignment swap
+5 pts 5m
Python Basics easy

Hello, name!

Implement a function that returns a personalized greeting for a given name.

strings function formatting
+5 pts 5m
Python Basics easy

Leap Year Checker

Implement a function that returns True if a year is a leap year according to the Gregorian calendar rules.

conditionals boolean modulo
+10 pts 10m
Python Basics easy

Absolute Difference

Implement a function that returns the absolute difference between two numbers.

absolute value arithmetic function
+5 pts 5m
Python Basics easy

Max of three numbers

Implement a function that returns the maximum of three numbers using comparisons.

conditionals comparison numbers
+10 pts 10m
Python Basics easy

Sign of a number

Write a function sign_of_number that returns -1 for negatives, 0 for zero, and 1 for positives.

conditionals numbers comparison
+5 pts 5m
Python Basics easy

Countdown printer

Implement a function that prints a countdown from a given number down to 1, then returns 'Go!'.

loops conditionals function-definition
+5 pts 5m
Python Basics easy

Sum from 1 to n

Write a function that returns the sum of all integers from 1 to n (inclusive).

math arithmetic sum
+5 pts 5m
Python Basics easy

Average of a list

Write a function that computes the average of a list of numbers, handling empty lists by returning 0.

average list statistics
+5 pts 5m
Python Basics easy

Find Minimum Value

Write a function that returns the minimum integer from a given list.

min list loop
+10 pts 10m
Python Basics easy

Range of values

Calculate the range (max minus min) of a list of numbers. Empty list returns 0.

min max numbers
+10 pts 10m
Python Basics easy

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.

division modulo conditionals
+10 pts 10m
Python Basics easy

Area of Rectangle

Write a function that returns the area of a rectangle given its width and height.

arithmetic function numbers
+5 pts 5m
Python Basics easy

Perimeter of triangle

Given three side lengths, return the perimeter (sum) of the triangle.

arithmetic geometry basics
+5 pts 5m
Python Basics easy

Volume of Cube

Write a Python function that returns the volume of a cube given its side length.

arithmetic return function
+5 pts 5m
Python Basics easy

Modulo Remainder

Implement a function that returns the remainder of a divided by b without using the modulo operator.

modulo arithmetic integers
+5 pts 5m
Python Basics easy

Print Pyramid Pattern

Implement a function that returns a centered asterisk pyramid as a list of strings.

loops strings pattern-printing
+10 pts 15m
Python Basics easy

Last Digit Extractor

Write a function that returns the last digit of a non-negative integer using the modulo operator.

integers modulo arithmetic
+5 pts 5m
Python Basics easy

Count word occurrences

Write a function that takes a sentence and returns a dictionary of word counts.

strings counting dictionaries
+10 pts 15m
Python Basics easy

Find Missing Number

Given a list of n distinct integers from 0..n with one missing, return the missing number.

math integers arrays
+10 pts 10m
Python Basics easy

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.

linear-search list index
+10 pts 15m
Python Basics easy

Validate date format

Return True if input string is exactly YYYY-MM-DD and a real calendar date.

validation strings dates
+10 pts 10m
Python Basics easy

Count Leading Zeros

Write a function that returns the number of leading zeros in a list of integers.

lists iteration counting
+8 pts 8m
Strings & Text easy

Reverse a string

Return the characters of the string in reverse order.

strings slicing
+5 pts 5m
Strings & Text easy

Palindrome check

Return True if the string reads the same forwards and backwards (ignoring case and non-alphanumeric).

strings two-pointer
+8 pts 8m
Strings & Text easy

Title case converter

Return the string with each word capitalised.

strings split
+5 pts 5m
Strings & Text easy

Anagram check

Return True if two strings are anagrams of each other.

strings sorting counter
+10 pts 10m
Strings & Text easy

Repeat each character n times

Given a string s and an integer n, return a new string where each character of s is repeated n times consecutively.

strings join comprehension
+8 pts 10m
Strings & Text easy

Longest word in a sentence

Write a function that returns the longest word from a sentence, with first-occurrence tie-breaking.

strings parsing split
+8 pts 10m
Strings & Text easy

Extract Digits Only

Given a string that may contain letters, symbols, and whitespace, extract all digits in order and return them as an integer.

strings digits parsing
+5 pts 5m
Strings & Text easy

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.

substring string searching
+10 pts 15m
Strings & Text easy

Interleave Two Strings

Given two strings s1 and s2, return a new string that interleaves them character by character, starting with s1.

strings merging loops
+8 pts 10m
Strings & Text easy

Sort characters alphabetically

Sort all characters in a string alphabetically and return the sorted string.

sorting string manipulation
+5 pts 5m
Strings & Text easy

Initials from a Full Name

Return the uppercase initials of each word in a given full name.

strings splitting uppercase
+8 pts 10m
Strings & Text easy

Is pangram?

Implement is_pangram(s) to return True if the string contains every letter from 'a' to 'z' at least once, ignoring case and non-alphabetic characters.

strings set validation
+8 pts 10m
Strings & Text easy

Remove Duplicates from String

Given a string, return a new string with each character that repeats consecutively reduced to a single occurrence.

strings loop filter
+8 pts 10m
Strings & Text easy

Longest Word Finder

Write a function that extracts alphabetic words from a string and returns the longest one, with ties broken by earliest position.

strings parsing max
+10 pts 10m
Strings & Text easy

Abbreviate Name

Create a function that takes a full name and returns an abbreviated version with initials and the last name.

strings formatting split
+10 pts 15m
Strings & Text easy

Mask email address

Given an email address, return a masked version that hides everything but the first and last character of the local part and the domain.

strings masking validation
+8 pts 10m
Strings & Text easy

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.

string search index
+10 pts 15m
Strings & Text easy

Sort characters in string

Write a function that sorts the characters in a string and returns the sorted string.

sorting string character
+8 pts 10m
Strings & Text easy

Most Common Character

Return the character that appears most frequently in a string, breaking ties by earliest occurrence.

strings counting dictionary
+10 pts 15m
Strings & Text easy

Index of First Occurrence

Implement a function that finds the starting index of a substring within a string, returning -1 when absent.

strings search index
+8 pts 12m
Strings & Text easy

Safe Command Executor

Implement emulate_run that simulates running a command list and returns output and exit code.

string-parsing simulation lists
+8 pts 10m
Strings & Text easy

Parse Log Line

Write a function that parses a log line and returns a dictionary with timestamp, level, and message.

string-parsing split strip
+10 pts 15m
Strings & Text easy

Split on camelCase

Given a camelCase string, split it into words at uppercase letters and return them as lowercase words.

strings parsing camelcase
+8 pts 10m
Strings & Text easy

Validate username format

Implement a function that validates a username according to length, allowed characters, and no consecutive underscores.

strings validation returns
+8 pts 12m
Lists & Arrays easy

Two Sum

Return indices (i, j) with i < j such that nums[i] + nums[j] == target.

dict complement
+18 pts 16m
Lists & Arrays easy

Remove duplicates (sorted)

Return a sorted list with duplicates removed.

arrays two-pointer
+10 pts 10m
Lists & Arrays easy

Running Product of Integers

Given a list of integers, return a new list where each element at index i is the product of all elements from index 0 to i.

prefix product lists
+10 pts 10m
Lists & Arrays easy

Second Largest Unique Value

Return the second largest distinct integer from a list, or None if it doesn't exist.

sorting unique arrays
+10 pts 10m
Lists & Arrays easy

Keep only even indexes

Given a list, return a new list containing only the elements at even indices (0, 2, 4, ...).

list slicing indexing
+5 pts 5m
Lists & Arrays easy

Running Maximum

Implement a function that returns a list where each element is the largest value seen so far.

lists cumulative maximum
+10 pts 15m
Lists & Arrays easy

Difference of Consecutive Elements

Given a list of numbers, return a new list where each element is the difference between consecutive elements.

list iteration math
+8 pts 10m
Lists & Arrays easy

Average excluding min and max

Return the average of a list after discarding the lowest and highest elements, handling edge cases.

lists statistics sorting
+7 pts 10m
Lists & Arrays easy

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.

zip lists pairs
+7 pts 10m
Lists & Arrays easy

Middle Element of an Odd-Length List

Implement a function that returns the middle element of an odd-length list.

lists indexing basic
+5 pts 5m
Lists & Arrays easy

Is Subset of Another List

Write a function that returns True if every element in a given list exists in another list, ignoring duplicates.

subset membership lists
+8 pts 12m
Lists & Arrays easy

Unzip pairs into two lists

Write a function that takes a list of pairs and returns two separate lists: first elements and second elements.

zip unpacking lists
+10 pts 10m
Lists & Arrays easy

Generate a Multiplication Table

Build a function that returns an n x n multiplication table as a list of lists.

nested-loops list-comprehension matrix
+10 pts 10m
Lists & Arrays easy

Majority Element Finder

Implement a function that returns the majority element in a list, which appears more than half the time.

majority frequency arrays
+10 pts 15m
Lists & Arrays easy

Intersection of Two Lists

Given two lists, return a sorted list of unique elements that appear in both lists.

intersection sorting unique
+10 pts 15m
Lists & Arrays easy

Union of Two Lists

Implement a function that combines two lists and returns only unique elements.

union list set
+10 pts 15m
Lists & Arrays easy

Difference of Two Lists

Write a function that returns items in list a that are not in list b, preserving order and duplicates.

lists difference counting
+8 pts 10m
Lists & Arrays easy

Wave sort array

Given a list of integers, reorder it into a wave pattern where elements alternate down-up, and return the new list.

sorting swap rearrangement
+10 pts 15m
Lists & Arrays easy

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.

lists indexing search
+10 pts 10m
Dicts & Sets easy

Word frequency

Return a dict mapping each word to its count in the sentence.

dict counter
+10 pts 10m
Dicts & Sets easy

List intersection

Return the sorted list of elements common to both lists.

sets intersection
+8 pts 8m
Dicts & Sets easy

Most frequent element

Return the element that appears most often in a list.

counter dict
+8 pts 8m
Dicts & Sets easy

Word to Index Map

Create a function that returns a dictionary mapping each unique word to the index of its first occurrence.

dictionary mapping indexing
+10 pts 10m
Dicts & Sets easy

Group names by first letter

Given a list of names, return a dictionary mapping each first letter to all names starting with that letter in original order.

dictionaries strings grouping
+10 pts 10m
Dicts & Sets easy

Keys Sorted by Value Descending

Given a dictionary mapping strings to integers, return a list of keys sorted by value descending, and when values tie, alphabetically ascending.

sorting dictionaries ordering
+8 pts 10m
Dicts & Sets easy

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.

dicts nested parsing
+8 pts 10m
Dicts & Sets easy

Common Keys of Two Dictionaries

Implement a function that finds keys shared by two dictionaries and returns them sorted.

dict set sorting
+8 pts 10m
Dicts & Sets easy

Union of Many Sets

Implement a function that takes any number of sets and returns a sorted list of their union.

sets union flatten
+10 pts 10m
Dicts & Sets easy

Mode of a list via counting

Implement a function that returns the mode of a list, resolving ties by the element that appears first.

counting dictionaries mode
+10 pts 15m
Dicts & Sets easy

Top k keys by count

Given a dictionary mapping keys to counts, return the top k keys with the highest counts, breaking ties alphabetically.

dictionary sorting frequency
+10 pts 15m
Dicts & Sets easy

Values that appear once

Return a list of numbers that appear exactly once in the input list, in original order.

counting filtering order
+10 pts 15m
Dicts & Sets easy

Two Sum with Dict

Implement the classic Two Sum problem: return indices of two numbers that add up to a target using a dict.

dictionary pair-sum hash-map
+10 pts 15m
Dicts & Sets easy

Anagram Groups by Size

Group a list of words into anagram groups and return them sorted by group size and lexicographically.

dicts sets sorting
+10 pts 10m
Dicts & Sets easy

Top K Frequent Words

Given a list of words, return the k most frequent words sorted by frequency (descending) and then alphabetically.

dictionary sorting frequency
+10 pts 15m
Dicts & Sets easy

Symmetric Difference

Write a function that computes the symmetric difference of two lists, returning a sorted list of unique elements.

sets set-operations symmetric-difference
+8 pts 10m
Data Structures & Algorithms easy

Valid parentheses

Return True if brackets in the string close in the correct order.

stack strings
+15 pts 14m
Data Structures & Algorithms easy

Binary search

Return the index of target in a sorted list, or -1 if not present.

searching binary-search
+12 pts 12m
Data Structures & Algorithms easy

Index of peak element

Implement a function that returns the index of any peak element in a given integer array.

arrays search peak
+10 pts 15m
Data Structures & Algorithms easy

Pascal Triangle Row

Given a non-negative integer n, return the nth row of Pascal's triangle as a list of integers.

math combinatorics arrays
+10 pts 15m
Decorators & Context Managers easy

Once Decorator: Run a Function Only Once

Implement a decorator that caches and returns the result of the first call for subsequent calls.

decorators closures caching
+8 pts 10m
Decorators & Context Managers easy

Print Args Decorator

Write a decorator that prints function name and arguments, then returns the original result.

decorators functions wrappers
+10 pts 10m
Error Handling & Exceptions easy

Safe Integer from String

Implement safe_int that converts a string to an integer, returning a default value on any failure, with support for an optional base.

exceptions parsing default-value
+10 pts 15m
Error Handling & Exceptions easy

Safe divide function

Implement safe_divide that returns None on ZeroDivisionError and TypeError.

try-except division error-handling
+8 pts 10m
Error Handling & Exceptions easy

Safe int parser

Implement safe_parse_int that converts a string to an int, returning a default value on failure.

exceptions parsing validation
+10 pts 10m
Error Handling & Exceptions easy

Safe Float Parser

Write a function that safely converts a string to a float, returning None for invalid inputs.

float exception parsing
+10 pts 10m
Error Handling & Exceptions easy

Key error handler

Implement a safe dictionary access function that returns a default value on missing keys.

exceptions dict fallback
+8 pts 10m
Error Handling & Exceptions easy

Else on try block

Implement a function that uses try-except-else to safely divide two numbers and return a result or error description.

exception-handling try-except-else division
+8 pts 10m
Math & Number Theory easy

Nth Triangular Number

Implement a function that returns the nth triangular number efficiently.

math formula integers
1
+10 pts 10m
Math & Number Theory easy

Integer Square Root Floor

Implement a function that returns the greatest integer whose square is ≤ n, using only integer operations.

math binary-search integer
+8 pts 12m
Math & Number Theory easy

Catalan number

Implement a function that returns the nth Catalan number using dynamic programming.

math dynamic-programming combinatorics
+10 pts 15m
Math & Number Theory easy

Sieve of Eratosthenes

Implement the Sieve of Eratosthenes to return a sorted list of all primes up to a given integer n.

primes sieve loops
+10 pts 15m
Math & Number Theory easy

Prime Factorization

Return a sorted list of prime factors of a positive integer, including repeated factors.

prime math loops
+10 pts 15m
Math & Number Theory easy

Sum of divisors

Given an integer n, return the sum of all its positive divisors.

divisors math number-theory
+10 pts 15m
Math & Number Theory easy

Perfect Number Check

Write a function that returns True if a number is perfect, i.e., equal to the sum of its proper divisors.

math divisors number-theory
+10 pts 15m
Math & Number Theory easy

Happy number check

Implement a function that returns True if a number is happy, False otherwise.

math loops set
+8 pts 12m
Math & Number Theory easy

Triangular Number

Implement a function that returns the nth triangular number using the closed-form formula.

triangular formula math
+10 pts 10m
Math & Number Theory easy

Pentagonal Number

Given a positive integer n, return the nth pentagonal number using the formula P(n) = n(3n - 1)/2.

math formula integer
+10 pts 10m
Math & Number Theory easy

Partition function

Write a function that returns the number of ways to write a positive integer as a sum of positive integers (order irrelevant).

math recursion memoization
+12 pts 15m
Bit Manipulation easy

Count Set Bits

Implement a function that returns the number of set bits (1s) in the binary representation of a non-negative integer.

bit-manipulation binary counting
+10 pts 15m
Bit Manipulation easy

Check Power of Two Bits

Implement is_power_of_two(n) that returns True if n is a power of two and False otherwise.

bitwise power-of-two integer
+8 pts 10m
Bit Manipulation easy

Single Number XOR

Given a non-empty list of integers where every element appears twice except one, return the single number using XOR.

xor bit-manipulation arrays
+10 pts 12m
Bit Manipulation easy

Missing Number XOR

Given a list of n distinct numbers from 0 to n with one missing, use XOR to find and return the missing number.

xor bitwise arrays
+10 pts 15m
Bit Manipulation easy

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.

bitwise bit-manipulation integer
+8 pts 12m
Bit Manipulation easy

Isolate Rightmost Set Bit

Given an integer, return a number with only its rightmost set bit set.

bit-manipulation bitwise algorithms
+10 pts 10m
Bit Manipulation easy

Set kth Bit

Implement a function that sets the kth bit (0-indexed) of a non-negative integer to 1 and returns the result.

bit-manipulation bits integer
+10 pts 15m
Dynamic Programming easy

Climbing Stairs

Implement a function that returns the number of distinct ways to climb n stairs using steps of 1 or 2.

fibonacci dp counting
+10 pts 15m
Dynamic Programming easy

House Robber

Given a list of house values, return the maximum sum you can rob without robbing two adjacent houses.

dynamic-programming arrays optimization
+10 pts 15m
Trees & Binary Trees easy

Binary Tree Inorder Traversal

Implement an inorder traversal function that returns node values in left-root-right order.

binary-tree traversal recursion
+10 pts 15m
Trees & Binary Trees easy

Preorder Traversal

Implement a function that returns the preorder traversal values of a binary tree.

binary-tree traversal recursion
+10 pts 10m
Trees & Binary Trees easy

Postorder Traversal

Implement a function that returns the postorder traversal of a binary tree as a list of node values.

binary-tree traversal recursion
+10 pts 15m
Trees & Binary Trees easy

Maximum depth of tree

Implement max_depth(root) to return the maximum depth of a binary tree.

binary-tree recursion depth
+10 pts 15m
Graphs & Graph Algorithms easy

Find the Town Judge

Given n people and a trust array, return the town judge or -1.

graph indegree outdegree
+10 pts 15m
Recursion & Backtracking easy

Permutation Generator

Write a function that returns all permutations of a list of distinct integers.

recursion backtracking permutations
+10 pts 15m
Two Pointers & Sliding Window easy

Longest Substring Without Repeating Characters

Implement a function that returns the length of the longest substring without repeating characters.

strings sliding-window two-pointers
+10 pts 15m
Stacks & Queues easy

Next Greater Element

Return a list where each position holds the next greater element to the right, or -1 if none exists.

stack arrays monotonic stack
+10 pts 15m
Datetime & Time Calculations easy

Days in month

Write a function that returns the number of days in a given month and year, correctly handling leap years.

datetime calendar leap-year
+8 pts 10m

Showing 144 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

  1. Pick a category — basics, algorithms, strings, and more
  2. Open a challenge, read the statement, and edit the starter code
  3. 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.