From Vibe Coding to Real Web and Python Code
You can name every start tag on a small page, compute two grid columns from a width and a gap, trace a submit handler that appends one list item, and step a Python function line by line, including the line that returns None.
- Level
- Navigator
- Time
- 24 h

Jump to
After this course you can
The student can implement a dependency-free Python and Vanilla JS application that passes a complete functional, boundary, and error-handling test suite.
Semantic HTML5, tag by tag
Open a page by naming the elements before the browser paints them. Semantic HTML5 uses element names that say what each region is for. The pantry page begins with a doctype declaration, then one html element whose lang attribute is en. The head holds a meta element with charset utf-8 and a title element whose text is Pantry. The browser chrome uses that title. The body holds a header, and the header holds one h1 whose text is also Pantry. That h1 is the heading inside the page. The main element holds the working area: a form whose id is add, and a ul whose id is items. The ul starts with no li children.
Inside the form, the label text is Item and the label's for attribute is item. The input's id is item, its name is item, and its type is text. The for value and the id value are the same string, so a click on the word Item moves the cursor into that input. The button text is Add and the button's type is submit. Inside a form, a button with no type attribute is a submit button too, so the written type keeps that job visible on the line. Count the start tags: html, head, meta, title, body, header, h1, main, form, label, input, button, ul. That is 13. The doctype is a declaration and stays outside the count.
Measure a CSS grid
Give main one layout rule: display grid, grid-template-columns 2fr 1fr, gap 24px, and width 720px. Leave padding unset. The default box is the content box, so the content box is 720 pixels wide and the gap sits inside it. main has two children, the form and the ul, so the form occupies the first column and the ul occupies the second, on one row. There is a single column gap of 24 pixels. Free space for the columns is 720 minus 24, which is 696. The track list is two fr plus one fr, three parts. 696 divided by 3 is 232. The first column is 464 pixels and the second is 232 pixels. Check the sum: 464 plus 24 plus 232 is 720.
The same steps work when you change the inputs. A width of 480 pixels, a gap of 16 pixels, and columns 1fr 1fr leave free space of 480 minus 16, which is 464. Two equal parts are 232 and 232. 232 plus 16 plus 232 is 480. A later rule can set grid-template-columns to 1fr when the window is narrow. Until that rule is in the file, the two columns stay side by side at the widths you computed. Write the width, the gap, and the fr counts in the rule, then do the subtraction on paper before you trust a generated stylesheet.
A submit handler in plain JavaScript
Vanilla JavaScript means the language in the page, with no library between your lines and the DOM. The DOM is the tree the browser built from the HTML. Number the handler. Line 1 registers it: form.addEventListener with the event name submit. Line 2 calls event.preventDefault, so the browser keeps this page and does not navigate. Line 3 reads document.querySelector("#item").value and calls trim on that string. Line 4 is if (text === "") return, which leaves the function before any new element exists. Line 5 calls document.createElement("li"), which builds an li that still has no parent. Line 6 sets li.textContent to text. Line 7 calls appendChild on the element from document.querySelector("#items").
Trace the field value made of two spaces, the letters oats, and two spaces. That value has 8 characters. trim removes the spaces at each end, so text is oats, 4 characters. Line 4's comparison is false, so the function continues. After line 7 the ul has one li and that li's text is oats. Now submit a field of three spaces. trim produces the empty string, line 4 returns, and the ul still has that one li. querySelector returns null when the id is missing or mistyped. Reading value on null throws a TypeError, so the id in line 3 has to match the id on the input.
textContent stores characters as text. The 11 characters of the string <b>oats</b> stay on screen, angle brackets included, and the document gains no b element. A different line builds markup: items.innerHTML = items.innerHTML + "<li>" + text + "</li>". With text oats, the added piece is the 13 characters of <li>oats</li>, and the browser parses an li. With text <b>oats</b>, the parser sees a b element inside that li. Setting innerHTML also replaces the existing children of the ul. A listener that had been attached to an old li goes away with that node. The textContent path on a fresh li leaves the old children in place.
fetch sends the same word to a path on this site. JSON.stringify of the object with one field item set to oats produces the 15 characters {"item":"oats"}. Put that string in the body, set the method to POST, and set the header Content-Type to application/json. Await that call before you create the li. response.ok is true when status is in the range 200 through 299, so a supposed status 200 continues to appendChild. A supposed status 400 makes ok false. Return on that line and the ul stays as it was. If fetch throws before a response arrives, the lines after the await do not run, and the child count stays where it was.
A Python function, annotations, and a venv
Match the page with a function you can run in Python 3.9 or newer. Line 1 is def add_item(items: list[str], text: str) -> list[str]. Line 2 is cleaned = text.strip(). Line 3 is if cleaned == "": raise ValueError("empty item"). Line 4 is return items + [cleaned]. On 3.9 and later, the annotation list[str] is accepted on the def line with no import. The annotations are read by a person and by a type checker. The interpreter still enters the function when the second argument is the integer 5. Line 2 then raises AttributeError, because an int has no strip method.
Call add_item with an empty list and the 8-character string of two spaces, oats, and two spaces. strip leaves oats. The comparison with the empty string is false, so line 4 runs. The plus builds a new list, ["oats"]. The list you passed in still has length 0. Call add_item with ["oats"] and three spaces. strip leaves the empty string, line 3 raises ValueError with the message empty item, and line 4 does not run. The list ["oats"] still has length 1. Call add_item with ["oats"] and tea. The returned list is ["oats", "tea"], length 2, and the list you passed in is still ["oats"].
A virtual environment is a folder with its own interpreter, often shortened venv. Where the interpreter is named python3, the command python3 -m venv .venv creates the folder .venv. On a Unix layout that interpreter is .venv/bin/python. On Windows it is .venv\Scripts\python.exe. A new environment starts with the standard library. add_item uses only that, so it runs there with no added package. Put the function in notes.py. In app.py, the line from notes import add_item binds the name. Run app.py from the folder that contains notes.py and Python loads the neighbor file. One file holds the rule. The other file holds the call.
Read every generated line
A chat service can print a shorter function with the same name. Line 1 is def add_item(items, text), with no annotations. Line 2 is cleaned = text.strip(). Line 3 is items.append(cleaned). Line 4 is return items. append changes the list object that was passed in, and the value append itself returns is None. The return on line 4 hands that same list back to the caller. Start from pantry = ["oats"] and same = pantry, then call this version with tea. pantry, same, and the returned value are one list, ["oats", "tea"], length 2. The plus version from the previous section leaves pantry as ["oats"] and returns a second list.
A one-line variant is return items.append(cleaned). The call still mutates the list, because append runs. The caller receives None, because that is what append returns, and there is no later line that returns items. Start again from ["oats"] and pass tea. After the call the list is ["oats", "tea"] and the returned value is None. The four-line version also stores an empty string when the text is three spaces, because it never compares cleaned with "". The version that raises ValueError stops before the return. Read a generated file by numbering the lines, naming what each line returns, and walking one input you can finish on paper.
One pantry item, from tags to the return value
Build the pantry page so the start-tag count is 13 and the ul is empty. Apply the grid rule of width 720, columns 2fr 1fr, and gap 24. The form sits in a column of 464 pixels. The ul sits in a column of 232 pixels. The person types two spaces, oats, and two spaces, then activates Add. preventDefault keeps the page. trim reduces the 8 characters to oats. The empty check is false. createElement makes an li with no parent, textContent stores oats, and appendChild makes the ul's child count 1.
Suppose a server is in play and the handler awaits fetch before appendChild. The body is the 15 characters {"item":"oats"}, the method is POST, and the Content-Type header is application/json. Suppose the status comes back 200. ok is true, and the ul ends with one li whose text is oats. Suppose instead the status comes back 400. ok is false, the handler returns, and the ul stays empty if that was the first submit. A throw from fetch, with the append placed after the await, also leaves the child count unchanged.
On the Python side, call add_item with [] and the same 8-character string. The returned list is ["oats"] and the argument list still has length 0. A second call, add_item(["oats"], " "), raises ValueError("empty item") and leaves ["oats"] at length 1. Passing the integer 5 reaches line 2 and raises AttributeError. The append version, called as return items.append(cleaned) with ["oats"] and tea, leaves the list as ["oats", "tea"] and gives the caller None.
Check it on paper
Use the grid steps. The container width is 480, the gap is 16, and the columns are 1fr 1fr. Write the free space and each column width. The ul starts empty and the handler trims. The field is two spaces, milk, and two spaces. Write the li text and the child count. The next field is three spaces. Write the child count after that submit. Call the plus version of add_item on the list ["milk"] with the string of a space, tea, and a space. Then call it on the list ["milk"] with three spaces. Then call add_item(["milk"], 5). For the 11 characters of <b>oats</b>, say what textContent shows and what the innerHTML concatenation parses. For return items.append(cleaned), start from ["oats"], pass tea, and write the returned value and the list afterward.
Free space is 464. Each column is 232. The li text is milk and the child count is 1. After the spaces-only submit the child count stays 1. add_item(["milk"], " tea ") returns ["milk", "tea"]. add_item(["milk"], " ") raises ValueError("empty item") and ["milk"] stays length 1. add_item(["milk"], 5) raises AttributeError on strip. textContent shows the 11 characters, and the page has no b element. The innerHTML line parses a b element inside an li. return items.append(cleaned) returns None, and the list is ["oats", "tea"].
Check questions
How many start tags does the pantry page contain, and does the doctype add one to that count?
13 start tags: html, head, meta, title, body, header, h1, main, form, label, input, button, and ul. The doctype is a declaration and stays outside that count.
main is 720 pixels wide, with grid-template-columns 2fr 1fr, gap 24px, and no padding. How wide is each column?
The first column is 464 pixels and the second is 232 pixels. Free space is 696, and 696 divided by 3 is 232.
The ul is empty and the handler trims. The person submits two spaces, oats, and two spaces, then submits three spaces. How many li children are there, and what text does the li hold?
One li, and its text is oats. The second submit trims to the empty string and returns before createElement.
What does the caller receive from return items.append(cleaned) when the list starts as ["oats"] and the text is tea, and what does the list hold afterward?
The caller receives None, because append returns None. The list holds ["oats", "tea"], because append already changed it.
Number the tags, subtract the gap from the width, walk one string through the handler, and name what each Python line returns. A generated file earns its place when those four checks agree with the lines on the page.
Final task
Submit a Python + HTML/JS application that passes 35 fixed unit and Playwright DOM tests covering empty inputs, malformed payloads, keyboard navigation, and deterministic state persistence.
Terms in this course
This course has no terms of its own in the glossary yet. Terms from earlier courses are used here too.
The first lesson is open to read. The rest of the course is being written, and tests and diplomas come later. Join the waitlist