Python Practice Problems for Beginners
Short exercises with solutions, coding challenges that check your answer with tests, and small project ideas, all solved in the browser. Start at the top and work down: each group builds on the one before.
How to practice
- Exercises show a worked solution: read it, run it, then change the input and predict the output before you run it again.
- Challenges give you only the problem. Your code runs against test cases, some of them hidden, and you see which pass. Running the tests needs a free account, which also keeps your progress.
- Projects are open-ended. Build the smallest version that works, then add one feature at a time.
- When you are stuck, step through your code in the visualizer or the debugger before looking at a solution.
Beginner exercises with solutions
27 classic problems: numbers, strings and lists. Each page has a runnable solution and an explanation.
- Fibonacci Series in Python
- Prime Number Program in Python
- Palindrome Program in Python
- How to Reverse a String in Python
- Factorial Program in Python
- How to Sort a List in Python
- Count Words and Word Frequency in Python
- Even or Odd Program in Python
- Sum Natural Numbers in Python
- Sum of Digits Program in Python
- How to Reverse a Number in Python
- Armstrong Number Program in Python
- Perfect Number Program in Python
- Leap Year Program in Python
- Multiplication Table Program in Python
- Temperature Converter in Python
- Simple Calculator Program in Python
- Count Vowels in Python
- Check If Two Strings Are Anagrams in Python
- Count Characters in a String in Python
- Find the Second Largest Value
- Python List Intersection: Find Common Elements
- How to Flatten a Nested List in Python
- Split a List into Chunks
- Remove Duplicates from a List in Python
- Check Password Strength
- Caesar Cipher in Python with Example Code
Challenges checked with tests
Solve them in Python (or another language you are learning). Easy ones first.
| Challenge | Level |
|---|---|
| Sum of Digits | Easy |
| Reverse a Number | Easy |
| Count Digits | Easy |
| Largest Digit | Easy |
| Smallest Digit | Easy |
| Factorial | Easy |
| Triangular Number | Easy |
| Square a Number | Easy |
| Odd, Even, or Neither | Easy |
| Fizz Buzz | Easy |
| Chess Square Color | Easy |
| Hours, Minutes, and Seconds | Easy |
| Median of a List | Easy |
| Leap Year | Easy |
| Count Handshakes | Easy |
| Collatz Sequence | Easy |
| Make an Array Nondecreasing | Easy |
| Sum of Multiples | Easy |
| Sum Even Fibonacci Terms | Easy |
| Difference of Squares | Easy |
| Doubling Grains on a Chessboard | Easy |
| Classify a Number by Its Divisors | Easy |
| Pascal’s Triangle | Easy |
| Pangram Check | Easy |
Python projects for beginners
- Number guessing gamerandom, while loops and input(): the computer picks a number and gives hints.
- Tip and bill splitterArithmetic, rounding and f-strings for money.
- To-do list in the terminalLists, a menu loop, and saving the list to a file.
- Word counterStrings, split() and a dictionary of counts, sorted by frequency.
- Password generatorrandom.choice, string constants and a few options for length and symbols.
- Quiz gameA list of questions and answers, a score, and a final message.
- Unit converterFunctions for temperature, distance and weight, chosen from a menu.
- Turtle drawingLoops and angles that draw stars, spirals and flowers, on the turtle page.
Warm-up: FizzBuzz
A classic first problem that uses a loop, the remainder operator % and if/elif. Open it in the editor, replace pass with your solution and run it.
# Practice: FizzBuzz
# Print the numbers from 1 to 20. For multiples of 3 print "Fizz",
# for multiples of 5 print "Buzz", and for multiples of both print "FizzBuzz".
for n in range(1, 21):
# Write your code here
pass
Learn the topics first
Frequently asked questions
Where can I practice Python for free?
The exercises and challenges on this page are free. Each one runs in the browser, and challenges check your answer with tests, so you know right away whether it works.
What should a beginner practice first?
Start with input and output, if statements and loops: even or odd, a multiplication table, the sum of digits. Then move to strings and lists: reversing, counting and removing duplicates.
How are challenges checked?
Your program runs against several test cases with known inputs and outputs, some of them hidden, and you see which ones pass.
Do I need an account?
Not for the exercises, the project ideas or the editor. Running a challenge's tests and submitting a solution need a free account, which saves your progress and solutions.
Are there harder problems?
Yes. The challenges go from easy to hard, including recursion, dynamic programming and graph problems.