Python Exercises
200 exercises with a Check button that tests your code. Each one links to the lesson that teaches it.
Start with the 50 practice problems
Classic problems from FizzBuzz to an LRU cache, in order of difficulty. Also on one page.
- FizzBuzz
- Reverse the Words
- Count the Vowels
- Palindrome Check
- Sum of Digits
- Largest Number Without max()
- Remove Duplicates, Keep the Order
- Second Largest Value
- Most Common Character
- Are They Anagrams?
- Factorial, With a Proper Error
- Is It Prime?
- Letter Grade
- Title Case Without .title()
- Common Elements
- Flatten a List of Lists
- Merge Two Inventories
- Invert a Dictionary
- Password Strength Check
- Average of Messy Input
- Fibonacci Generator
- Sieve of Eratosthenes
- Caesar Cipher
- Top Words in a Text
- Group the Anagrams
- Balanced Brackets
- Run-Length Encoding
- Binary Search
- Merge Two Sorted Lists
- Rotate a List
- Deep Flatten
- Roman Numerals
- Longest Common Prefix
- Parse a Log Line With Regex
- A Bank Account Class
- Two Sum
- Longest Substring Without Repeats
- Merge Overlapping Intervals
- Top K Frequent Elements
- Maximum Subarray (Kadane)
- Coin Change (Dynamic Programming)
- Longest Increasing Subsequence
- Shortest Path in a Graph (BFS)
- LRU Cache
- Trie for Autocomplete
- Write a Memoize Decorator
- A Retry Decorator With Arguments
- A Context Manager That Cleans Up
- Revenue by Region With pandas
- Leaderboard With a Dataclass
Python Fundamentals
for Beginners
- Print a GreetingBeginner
- Restaurant BillBeginner
- Personal IntroductionBeginner
- Fix the Bug: Broken CalculatorBeginner
Variables and Data Types
- Create Variables of Each TypeBeginner
- Temperature ConverterBeginner
- Predict the Output: Truthy or Falsy?Beginner
- Fix the Bug: String + Number CrashBeginner
- Swap Two VariablesBeginner
- Type Conversion ChainBeginner
Numbers
- Calculate the Total CostBeginner
- Even or Odd CheckerBeginner
- Fix the Bug: Wrong DivisionBeginner
- Fahrenheit to Celsius ConverterBeginner
- Predict the OutputBeginner
- Compound Interest CalculatorBeginner
Strings
- Build a Greeting with ConcatenationBeginner
- Get the First and Last CharacterBeginner
- Reverse a StringBeginner
- Predict the Slice OutputBeginner
- Fix the Bug: Mutating a StringBeginner
- Check If a Word Is in a SentenceBeginner
- Extract a Domain from an Email AddressBeginner
string methods
- Clean Up User InputBeginner
- Count Word OccurrencesBeginner
- Replace All OccurrencesBeginner
- Split a CSV LineBeginner
- Fix the Bug -- find() vs index()Beginner
- Validate a UsernameBeginner
String Formatting
- Format a Receipt LineBeginner
- Format a Large Number with CommasBeginner
- Create a Formatted Table RowBeginner
- Fix the Broken f-stringBeginner
- Generate a Personalized Email GreetingBeginner
booleans and operators
- Check if a Number Is in RangeBeginner
- Validate a String LengthBeginner
- Predict the Logical OutputBeginner
- Fix the Comparison BugBeginner
- Check for a Leap YearBeginner
- Evaluate Truthiness with bool()Beginner
Input and Output
- Print with a Custom SeparatorBeginner
- Print Items on the Same LineBeginner
- Create a Multiplication TableBeginner
- Print a Formatted ReceiptBeginner
Control Flow
if else
- Even or OddBeginner
- Temperature AdvisorBeginner
- Predict the OutputBeginner
- Fix the Grade CalculatorBeginner
- Ternary Ticket PriceBeginner
- Login ValidatorBeginner
For Loops
- Print the Shopping ListBeginner
- Sum Numbers 1 to 10Beginner
- Predict the OutputBeginner
- Fix the Bug: Letter CounterBeginner
- Numbered MenuBeginner
- Reverse a StringBeginner
- Student Grade ReportBeginner
While Loops
- Countdown TimerBeginner
- Power of 2 FinderBeginner
- Predict the OutputBeginner
- Fix the Bug: Digit CounterBeginner
- The Collatz SequenceBeginner
break, continue, pass
- Find the First Negative NumberBeginner
- Print Without VowelsBeginner
- Predict the OutputBeginner
- Fix the Bug: Sum Until NegativeBeginner
- Password Checker with for-elseBeginner
Nested Loops
- Print a RectangleBeginner
- Predict the OutputIntermediate
- Number TriangleIntermediate
- Sum All Grid ValuesIntermediate
- All Outfit CombinationsIntermediate
- Fix the Coordinate GridIntermediate
error messages
- Fix the SyntaxErrorBeginner
- Fix the NameErrorBeginner
- Fix the TypeErrorBeginner
- Fix the IndexErrorBeginner
- Fix the ValueErrorBeginner
- Fix All the BugsBeginner
Data Structures
Lists
- Create a List and Print Its LengthBeginner
- Access the Last Item with Negative IndexingBeginner
- Shopping List: Add and Remove ItemsBeginner
- Fix the Bug: IndexErrorBeginner
- Sum All Numbers Using a LoopBeginner
- Find the Largest Number Without max()Intermediate
- Predict the Output: List AliasingIntermediate
- Reverse a List Without reverse() or [::-1]Intermediate
Comprehensions
- Double Every NumberBeginner
- Filter Even NumbersBeginner
- Predict the Output: if vs if-elseIntermediate
- Create a Dict ComprehensionIntermediate
- Unique Vowels with a Set ComprehensionIntermediate
- Fix the Bug: Wrong Comprehension SyntaxIntermediate
- Refactor a Loop into a ComprehensionIntermediate
- Flatten a MatrixAdvanced
Tuples
- Create a Tuple and Access ElementsBeginner
- Predict the Output: Single Item TupleBeginner
- Unpack a TupleBeginner
- Fix the Bug: Modifying a TupleBeginner
- Loop and Unpack Student ScoresIntermediate
Dictionaries
- Create a Dictionary and Access a ValueBeginner
- Add and Modify Dictionary EntriesBeginner
- Safe Access with get()Beginner
- Loop Through a DictionaryBeginner
- Predict the Output: Duplicate KeysBeginner
- Fix the Bug: Checking for a ValueIntermediate
- Build a Word CounterIntermediate
- Access Nested Dictionary DataIntermediate
Sets
- Remove Duplicates from a ListBeginner
- Predict the Set OutputBeginner
- Find Students in Both ClassesIntermediate
- Fix the Empty Set BugIntermediate
- Find Missing IngredientsIntermediate
- Deduplicate While Preserving OrderAdvanced
Slicing
- Get the Middle ItemsBeginner
- Predict the Slice OutputBeginner
- Extract Even-Indexed ItemsIntermediate
- Reverse a WordBeginner
- Fix the Slicing BugIntermediate
- Palindrome CheckerAdvanced
Unpacking
- Unpack a CoordinateBeginner
- Swap Two VariablesBeginner
- Head and Tail with StarIntermediate
- Predict the Unpacking OutputIntermediate
- Unpack Student RecordsAdvanced
Sorting
- Sort a List of NumbersBeginner
- Predict the Output: sort() vs sorted()Beginner
- Sort Words by LengthIntermediate
- Fix the Bug: Case-Sensitive SortingIntermediate
- Sort Students by GradeIntermediate
- Sort by Multiple CriteriaAdvanced
nested data
- Access Nested List ItemsBeginner
- Predict the Output: Nested Dict AccessBeginner
- Find the Highest ScorerIntermediate
- Group Words by First LetterIntermediate
- Fix the Bug: Nested List TrapIntermediate
- Calculate Class AveragesAdvanced
Copy vs Deepcopy
- Predict the Output: Assignment AliasingBeginner
- Make an Independent CopyBeginner
- Predict the Output: Shallow Copy TrapIntermediate
- Safe Copy of Nested DataIntermediate