$ cd ../ (all courses)

Python

Readable, batteries-included, runs in your browser via Pyodide.

About Python

Python is a high-level, dynamically typed language designed for readability. It's used everywhere — web, data science, scripting, automation, AI. In this course, your code runs FOR REAL inside your browser using Pyodide (CPython compiled to WebAssembly).

Quick-reference cheat sheet
# Python cheat-sheet (the bits you'll need)

# Comments start with #
print("hello")              # output
x = 42                      # variables — no type annotation needed
name = "ada"                # strings: "..." or '...'
pi = 3.14                   # floats
ok = True                   # booleans (True/False)
nothing = None              # null

# f-strings
print(f"x={x}, name={name}")

# Math
2 + 3        # 5
2 ** 8       # 256 (power)
7 // 2       # 3  (integer division)
7 % 2        # 1  (modulo)

# Conditions (indentation matters!)
if x > 0:
    print("positive")
elif x == 0:
    print("zero")
else:
    print("negative")

# Loops
for i in range(5):       # 0..4
    print(i)

while x > 0:
    x -= 1

# Lists / tuples / dicts / sets
nums = [1, 2, 3]
nums.append(4)
point = (1, 2)
person = {"name": "ada", "age": 36}
unique = {1, 2, 3}

# Comprehensions
squares = [n*n for n in range(5)]
evens = {n for n in nums if n % 2 == 0}
lookup = {n: n*n for n in range(5)}

# Functions
def add(a, b):
    return a + b

# Reading input from stdin
line = input()           # one line of input
n = int(input())         # parse to int

Tasks

  1. 01
    Hello, World!
    Print exactly: Hello, World!
    intro
  2. 02
    Greet the user
    Read a name from stdin and print: Hello, <name>!
    intro
  3. 03
    Add two numbers
    Read two ints on separate lines, print their sum.
    intro
  4. 04
    Area of a rectangle
    Read width and height, print area.
    intro
  5. 05
    Celsius → Fahrenheit
    Convert temperature.
    intro
  6. 06
    FizzBuzz
    Classic FizzBuzz from 1 to 15.
    easy
  7. 07
    Reverse a string
    Reverse the input line.
    easy
  8. 08
    Sum of evens
    Sum all even numbers from 1 to N.
    easy
  9. 09
    Max of three
    Print the largest of three numbers.
    easy
  10. 10
    Count vowels
    Count vowels in a line.
    easy
  11. 11
    Average of a list
    Print the average of space-separated numbers.
    easy
  12. 12
    Palindrome check
    Print "yes" if the input is a palindrome, otherwise "no".
    medium
  13. 13
    Fibonacci
    Print the first 10 Fibonacci numbers, comma-separated.
    medium
  14. 14
    Is it prime?
    Print "prime" or "not prime".
    medium
  15. 15
    List comprehension: squares
    Print squares of 1..10 space-separated.
    medium
  16. 16
    Letter frequency
    Count occurrences of letter 'a' in a string.
    medium
  17. 17
    Factorial
    Compute n! for n on stdin.
    medium
  18. 18
    Greatest common divisor
    GCD of two integers.
    medium
  19. 19
    Sort words
    Sort the words of a line alphabetically.
    medium
  20. 20
    Anagram check
    Two words on two lines — anagrams?
    medium
  21. 21
    Second largest
    Find the second-largest distinct number.
    medium
  22. 22
    Decimal → binary
    Convert N to binary.
    medium
  23. 23
    Most common word
    Find the most frequent word in a sentence.
    hard
  24. 24
    Transpose a matrix
    Transpose a 3x3 matrix from stdin.
    hard
  25. 25
    Recursive list sum
    Recursively sum a list.
    hard
  26. 26
    Parse JSON
    Parse a JSON object and print a value.
    hard
  27. 27
    Class: BankAccount
    Define a class with deposit/withdraw.
    hard
  28. 28
    Write a decorator
    A decorator that doubles a function's return value.
    hard
  29. 29
    Generator: fibonacci
    Define a generator yielding fibonacci numbers.
    hard
  30. 30
    ROT13 cipher
    Apply ROT13 to input.
    hard
  31. 31
    Strip & title-case
    Clean up a messy name string.
    easy
  32. 32
    Middle slice
    Print everything except first and last element.
    easy
  33. 33
    Inventory total
    Sum dictionary values.
    easy
  34. 34
    Comma code
    Join a list with commas and 'and'.
    easy
  35. 35
    Collatz sequence
    Print the Collatz sequence until it reaches 1.
    medium
  36. 36
    Streak finder
    Detect a run of 6 identical chars.
    medium
  37. 37
    Regex: extract phone
    Find a US-style phone number in text.
    medium
  38. 38
    Regex: extract emails
    Find all emails in text.
    medium
  39. 39
    Strong password check
    Validate password strength.
    medium
  40. 40
    Right-aligned table
    Format a column-aligned table.
    medium
  41. 41
    ASCII zigzag
    Print 5 lines of a zigzag wave.
    medium
  42. 42
    CSV: sum column
    Parse CSV from stdin and sum a column.
    medium
  43. 43
    JSON: pretty print keys
    List sorted keys of a JSON object.
    medium
  44. 44
    Days between dates
    Compute date difference in days.
    medium
  45. 45
    Roman numeral converter
    Convert an integer (1..3999) to Roman numerals.
    hard
  46. 46
    Caesar cipher (shift N)
    Encrypt with arbitrary shift.
    hard
  47. 47
    Mini key-value store
    Implement a tiny stdin-driven KV store.
    hard
  48. 48
    Bullet pointer
    Add * to start of every input line.
    hard
  49. 49
    Picture grid (rotate 90°)
    Rotate an ASCII picture 90° clockwise.
    hard
  50. 50
    Mad Libs replacer
    Replace ADJECTIVE/NOUN/VERB placeholders.
    hard
  51. 51
    Regex strip function
    Strip given characters using regex.
    hard
  52. 52
    Score a dice roll
    Score a Yahtzee-style roll.
    hard
  53. 53
    Sudoku row validator
    Check if 9 numbers form a valid Sudoku row.
    hard
  54. 54
    Balanced brackets
    Check (), [], {} are balanced.
    hard
  55. 55
    Spreadsheet totals
    Aggregate sales by product (ATBS Ch.13).
    hard
  56. 56
    Greedy coin change
    Make change with fewest US coins.
    hard
  57. 57
    Game of Life: one step
    Compute next generation of a 5x5 grid.
    hard
  58. 58
    Decode an intercepted base64 blob
    Read one base64 string from stdin, print its decoded ASCII value.
    easy
  59. 59
    Hex dump → readable string
    Convert a hex-encoded ASCII string from stdin into the original text.
    easy
  60. 60
    Hash a candidate password (MD5)
    Read a password from stdin and print its MD5 hex digest.
    easy
  61. 61
    Fingerprint a token (SHA-256)
    Print the SHA-256 hex digest of the stdin string.
    easy
  62. 62
    Defang malicious URLs
    Replace 'http' with 'hxxp' and '.' with '[.]' on every URL.
    easy
  63. 63
    Spot dropped malware by extension
    Count how many filenames in stdin end with a suspicious extension.
    medium
  64. 64
    Map ports to common services
    For each port number in stdin, print the well-known service name (or 'unknown').
    medium
  65. 65
    How many usable hosts in this CIDR?
    Read an IPv4 CIDR like 192.168.1.0/24 and print the number of usable host addresses.
    medium
  66. 66
    Failed-login frequency per IP
    From sshd 'Failed password ... from <ip>' lines, print 'ip count' sorted by count desc, then ip asc.
    medium
  67. 67
    Flag brute-force IPs
    Print every IP with at least 3 failed-login attempts, sorted ascending.
    medium
  68. 68
    Catch obvious SQL injection
    Count how many input lines contain an obvious SQLi pattern.
    medium
  69. 69
    Classify visitors by OS
    From a list of User-Agent strings, output Windows/Linux/Mac/Other counts in that fixed order.
    medium
  70. 70
    Crack a Caesar cipher
    Try every shift 1..25 and print the decryption that contains the word 'the'.
    medium
  71. 71
    Tiny dictionary MD5 cracker
    Given a target MD5 and a wordlist on stdin, print the matching word (or 'not found').
    hard
  72. 72
    Recover a single-byte XOR key
    Brute-force every byte key, find the one whose decryption is printable English with 'the '.
    hard
  73. 73
    Decode a JWT (no signature check)
    Split a JWT, decode header + payload (base64url), print 'alg=...' and 'sub=...'.
    hard
  74. 74
    Build a XOR + base64 payload
    Read one line, XOR every byte with 0x42, print the result base64-encoded.
    hard
  75. 75
    Triage an access log
    Parse 'METHOD path status' lines, print totals + 2xx/4xx/5xx + most-hit path.
    hard
  76. 76
    Roll up a port scan into a report
    Group 'host port status' lines, print 'host: p1,p2' for hosts with at least one open port.
    hard
  77. 77
    Extract a hidden LSB message
    From a sequence of integers, take each LSB and assemble bytes (MSB-first) to recover ASCII.
    hard
  78. 78
    Boss fight: end-to-end brute-force triage
    From sshd logs, find IPs with ≥3 failures, SHA-1 hash each, print 'ip:hash' sorted by IP.
    hard
  79. 79
    Automation: strip trailing whitespace
    Read every line from stdin and print it back without trailing spaces or tabs.
    easy
  80. 80
    Automation: batch-rename with date prefix
    Prefix every filename with the date from line 1 — e.g. 2024-01-15_report.txt.
    easy
  81. 81
    Automation: find TODO line numbers
    Print 1-indexed line numbers of every line containing TODO.
    easy
  82. 82
    Automation: collapse consecutive blank lines
    Collapse any run of blank lines into a single blank line.
    easy
  83. 83
    Automation: filter CSV by age
    Read a CSV with header name,age and print names where age >= 18 (input order).
    medium
  84. 84
    Automation: extract ERROR log lines
    Print only the log lines whose level is ERROR.
    medium
  85. 85
    Automation: filter log entries by time window
    Line 1 is 'HH:MM HH:MM'. Print messages whose time falls inside (inclusive).
    medium
  86. 86
    Automation: parse URL query string
    Parse a query string and print key=value lines sorted by key.
    medium
  87. 87
    Automation: dedupe emails (case-insensitive)
    Print each email exactly once (lowercased), in first-seen order.
    medium
  88. 88
    Automation: build a markdown TOC
    Turn '#' and '##' headings into an indented bullet list.
    medium
  89. 89
    Automation: key/value lookup
    Parse 'key: value' lines, then look up the key on the LAST line.
    medium
  90. 90
    Automation: TSV → JSON array
    Convert tab-separated values (with header) to a JSON array. Use sort_keys=True.
    medium
  91. 91
    Automation: log rotation plan
    Given log filenames, print 'old -> new' rotation mappings.
    medium
  92. 92
    Automation: find duplicate files by hash
    Group 'name,sha256' rows; print groups with 2+ files as 'hash: f1,f2,...'.
    hard
  93. 93
    Automation: count overlapping meetings
    Count pairs of meetings whose time ranges overlap.
    hard
  94. 94
    Automation: validate CSV rows
    Print the 1-indexed data-row numbers of rows where email lacks @ or age is not 0-120 int.
    hard
  95. 95
    Automation: render a {{var}} template
    Line 1 is JSON vars. Replace {{key}} placeholders in the rest.
    hard
  96. 96
    Automation: next cron-style run time
    Given the current HH:MM and a list of daily HH:MM jobs, print the next run.
    hard
  97. 97
    Automation: extract unique emails from text
    Find all emails in messy text; print unique (lowercase) sorted alphabetically.
    hard
  98. 98
    Automation: CSV pivot by category
    Sum amount per category and print 'category=total' sorted by total desc, alpha tiebreak.
    hard
  99. 99
    Automation: top-3 products by revenue
    From a sales CSV, compute revenue=qty*price per product and print top 3.
    hard
  100. 100
    Automation capstone: log report
    Build a 4-line summary from a structured log CSV.
    hard