Practice Python

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

  1. Exercises show a worked solution: read it, run it, then change the input and predict the output before you run it again.
  2. 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.
  3. Projects are open-ended. Build the smallest version that works, then add one feature at a time.
  4. 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.

Challenges checked with tests

Solve them in Python (or another language you are learning). Easy ones first.

All Python challenges →

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.

fizzbuzz.py
fizzbuzz.py
# 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.