Kodewick
Start learning →

Online Python Compiler

Free, nothing to install, no sign-in. Run it, then watch it run: every variable, step by step.

Try:
Online Python CompilerFull screen · your code and output are still here
Python
Examples
factorial.py
def factorial(n):
    if n <= 1:
        return 1
    return n * factorial(n - 1)

for i in range(1, 6):
    print(i, factorial(i))
Output

Press Run to see the result

Not just run

Watch your Python run: variables, calls and objects, step by step

Press play or drag the slider. What changed in a step lights up yellow; the step that fails is red. This is the real player, no sign-in.

▶ Plays right here, no sign-in
Debug & share

Run it, pause it, replay it, share it

As handy as VS Code on your computer, plus what it does not have: every step drawn.

Step

One line at a time, every value beside it

Press Step and the code stops at each line: the lit line runs next, and every variable’s value sits beside it. Go back too, with the ← → keys.

One line at a time, every value beside it
Replay an error

It crashed? See exactly how it went wrong

Under the error, press “See how it went wrong”: the visualizer opens at the failing step, in red, with the reason in plain words. Step back through everything before it.

It crashed? See exactly how it went wrong
Share

A link, a GIF, a picture of the code: post it to X

A link opens this very code. Or export a GIF of it running (light or dark, wide or tall) or a picture of the code, and post it to X, a chat, or embed it in a blog.

A link, a GIF, a picture of the code: post it to X
Examples

12 Python examples: one click runs them above

Each one can be stepped through and visualized. Change it, run it again.

FizzBuzz

The classic warm-up: a loop and if / elif.

for i in range(1, 16):
    if i % 15 == 0:
        print("FizzBuzz")
    elif i % 3 == 0:
        print("Fizz")
    elif i % 5 == 0:
        print("Buzz")
    else:
        print(i)

List comprehensions

A table of squares in one line, next to the loop it replaces.

squares = [n * n for n in range(6)]
print(squares)

evens = [n for n in squares if n % 2 == 0]
print(evens)

# the same, with a loop
loop = []
for n in range(6):
    loop.append(n * n)
print(loop == squares)

Counting with a dict

How many times each letter appears in a sentence.

text = "hello kodewick"
count = {}
for ch in text:
    if ch != " ":
        count[ch] = count.get(ch, 0) + 1

for ch, n in sorted(count.items()):
    print(ch, n)

Recursive factorial

Open it in the visualizer: the call stack grows, then unwinds.

def factorial(n):
    if n <= 1:
        return 1
    return n * factorial(n - 1)

for i in range(1, 6):
    print(i, factorial(i))

Fibonacci with memoization

Why the same number is never worked out twice.

memo = {}

def fib(n):
    if n in memo:
        return memo[n]
    if n < 2:
        return n
    memo[n] = fib(n - 1) + fib(n - 2)
    return memo[n]

print([fib(i) for i in range(10)])

Binary search

The range halves each step: step through it and watch lo and hi.

def search(xs, x):
    lo, hi = 0, len(xs) - 1
    while lo <= hi:
        mid = (lo + hi) // 2
        if xs[mid] == x:
            return mid
        if xs[mid] < x:
            lo = mid + 1
        else:
            hi = mid - 1
    return -1

print(search([2, 5, 8, 12, 16, 23, 38], 16))

Bubble sort

Switch the list to bars and watch neighbours swap.

xs = [5, 2, 9, 1, 7]
for i in range(len(xs)):
    for j in range(len(xs) - 1 - i):
        if xs[j] > xs[j + 1]:
            xs[j], xs[j + 1] = xs[j + 1], xs[j]
print(xs)

Classes and objects

Who self is, plain to see in the visualizer.

class Dog:
    def __init__(self, name):
        self.name = name
        self.tricks = []

    def learn(self, trick):
        self.tricks.append(trick)

rex = Dog("Rex")
rex.learn("sit")
rex.learn("roll over")
print(rex.name, rex.tricks)

A linked list

Nodes and arrows, drawn in a row.

class Node:
    def __init__(self, val, next=None):
        self.val = val
        self.next = next

head = None
for v in [3, 2, 1]:
    head = Node(v, head)

node = head
while node:
    print(node.val)
    node = node.next

Handling errors

try / except: something goes wrong, the program carries on.

for d in [2, 0, 5]:
    try:
        print(10 / d)
    except ZeroDivisionError:
        print("cannot divide by zero")

Reading input

input() waits; answer it right in the output panel.

name = input("What is your name? ")
age = int(input("How old are you? "))
print(name, "will be", age + 1, "next year")

Turtle drawing

turtle draws right in the browser.

import turtle

t = turtle.Turtle()
for _ in range(5):
    t.forward(100)
    t.right(144)
Three steps

How to run Python online

  1. 1
    Write code, or pick an exampleThe editor works like VS Code: completion, matching brackets, Ctrl+/ to comment.
  2. 2
    Press Run, or Ctrl + EnterThe output shows beside the code; when the program calls input(), answer it right there.
  3. 3
    To see how it runs: Step, or VisualizeYour code is kept in this browser; find it again in My code.
What works

Python, running in your browser

✓ Works

  • Python 3: classes, generators, decorators, f-strings
  • input() and print()
  • Common modules: math, random, collections, itertools, datetime, json
  • turtle drawing
  • Error messages as in CPython

✕ Not yet

  • pip packages (numpy, pandas …)
  • Files on your computer
  • The network (requests, sockets)
  • Programs that never end (stopped after a while)
FAQ

About the online Python compiler

Is it free? Do I need an account?

No and no. Open the page and write; your code stays in your own browser, nothing is uploaded.

Does it work on a phone?

Yes. Tap the code to write full screen, with a key row for Tab, brackets and colons; the output slides up from below.

My program asks for input(). Where do I type?

When it reaches input(), a box appears in the output: type the answer, press Enter, and it carries on.

How is it different from Python on my computer?

The language and its error messages are the same. You cannot install packages or read your files, which is plenty for learning, exercises and algorithms.

What does the visualizer show?

Every variable, every call frame, and arrows between lists, dicts and objects. Linked lists, trees and grids are drawn by their shape; a list of numbers can be shown as bars.

My code crashed. Can I see why?

Under the error, press "See how it went wrong": the visualizer opens at the failing step, in red, and you can step back to see how it got there.

Where is my code kept?

In this browser: My code keeps every file. Clearing the browser’s data removes it, so share anything important as a link.

How do I share my code?

Share → Copy link: whoever opens it gets the same code, no sign-in. You can also export a GIF of it running, or a picture of the code, and post it to X.

More

Four more languages, the same tools