Reference
Errors explained, concepts you can step through, cheatsheets and the glossary, with practice at the end.
/
Errors
When your code stops with a message: what it means and how to find it.
Python
NameErrorA line uses a name Python has never been given.DoneWebReferenceErrorA line uses a name that does not exist where it runs.DoneSQLno such columnThe table has no column with that name.DoneCundeclaredA line uses a name the compiler has not seen yet.DonePythonTypeErrorAn operation got the wrong kind of value.DoneWebCannot read properties of undefinedA property was read from undefined or null.DoneSQLno such tableThe database has no table with that name.DoneC';' expectedThe compiler wanted a symbol, often missing on the line above.DonePythonIndexErrorA list or string was asked for a position it does not have.DoneWebis not a functionSomething that is not a function was called with brackets.DoneSQLsyntax errorThe query breaks SQL grammar at or just before the word it names.DoneCmemory access out of boundsThe program touched memory past an array or through a bad pointer.DonePythonAttributeErrorThe value has no method or attribute with that name.DoneWebAssignment to constant variableA line tried to give a const a new value.DoneSQLambiguous column nameTwo joined tables share a column name and the query did not say which.DoneCdivide by zeroA whole number was divided by 0 while the program ran.DonePythonIndentationErrorThe spaces at the start of a line do not fit the block.DoneWebSyntaxErrorJavaScript could not read the code, so nothing ran.DoneSQLmisuse of aggregateCOUNT, SUM or AVG was used where single rows are tested.DoneCMaximum call stack size exceededA function kept calling itself and never stopped.DonePythonKeyErrorA dictionary was asked for a key it does not have.DonePythonSyntaxErrorPython could not read the code, so nothing ran.DonePythonValueErrorThe type is right, but the value cannot be used.DonePythonZeroDivisionErrorSomething was divided by zero.DoneConcepts
One idea per page, with code to run and a picture of what happens.
PythonLists and positionsA Python list keeps values in order. Read items by position, count from the end with negative indexes, take slices and change the list in place.Step through itDoneWebArraysAn array keeps values in order. Read them by index from 0, add with push, count with length and walk through them with for...of.DoneSQLJOIN: two tables into one resultA JOIN pairs rows from two tables wherever a column matches. INNER keeps only the pairs; LEFT keeps every row of the first table.Step through itDoneCArrays in memoryA C array is a row of same-sized values packed side by side in memory. Indexes start at 0, and nothing stops you walking off the end.Step through itDonePythonLoops that build a resultA for loop runs the same lines once for each item. Pair it with a total or a new list that grows on every pass to turn many values into one answer.Step through itDoneWebValues and typesEvery JavaScript value has a type. typeof tells you which, and the type decides whether + adds two numbers or glues two strings together.DoneSQLAggregates, GROUP BY and HAVINGCOUNT, SUM, AVG, MIN and MAX squash rows into one number. GROUP BY gives one row per group, and HAVING filters the groups after WHERE has filtered the rows.DoneCPointers and addressesEvery variable lives at an address. A pointer is a variable that holds one, and * follows it to the value that lives there.Step through itDonePythonNames and valuesA Python variable is a name that points at a value. Two names can point at the same value, and that matters once the value can change.Step through itDoneWeblet, const and block scopeWhen to use let and when to use const, what reassigning means, and why a variable made inside curly braces vanishes after them.DoneSQLNULL, the missing valueNULL means "unknown", not zero or empty. Why = NULL never matches, how IS NULL and COALESCE work, and what NULL does to COUNT and AVG.DoneCThe stack and the heapLocal variables live on the stack and vanish when their function returns. malloc gives you heap memory that stays until you free it.Step through itDoneLockedPythonDictionariesA dictionary maps keys to values, like item names to counts or usernames to scores. Look up, add, update and loop over pairs.Step through itDoneLockedWebThe box modelEvery element is a box of content, padding, border and margin. box-sizing decides whether width means the content or the whole box.DoneSQLSELECT, columns and aliasesSELECT picks which columns come back from a table, can work out new ones from them, and AS gives any column the name you want.DoneCCompiling a C programC source is text. A compiler turns it into a program the machine runs, and if it cannot, nothing runs at all. Learn the two kinds of error.DonePythonFunctions and return valuesA function is a named block you can run with different inputs. Parameters carry values in, return carries one value back out.Step through itDoneLockedWebPromises, async and awaitSome work finishes later. setTimeout, promises and async/await let your code wait for a timer or a server without freezing the page.DoneLockedSQLFiltering rows with WHEREWHERE keeps only the rows that pass a test. Combine tests with AND and OR, and match patterns, lists and ranges with LIKE, IN and BETWEEN.DoneCTypes and sizesEvery C value has a type that fixes its size in bytes. See int, char and double, measure them with sizeof, and watch an int overflow.DonePythonStrings and textStrings hold text. Index and slice them like lists, tidy them with methods, and build messages with f-strings. Methods never change the original.DoneWebThe DOM and eventsFind elements with querySelector, react to clicks and typing with addEventListener, and change what the page shows with textContent.DoneLockedSQLSubqueriesA subquery is a SELECT inside another query. Use one as a single value, as a list for IN, or as a table in FROM, and know when it runs once per row.DoneLockedCStrings are char arraysA C string is an array of chars that ends with a 0 byte. See why strlen and sizeof disagree, and why the array needs one extra box.DoneLockedPythonCatching errors with try and exceptSome errors are going to happen, like a typo in a number. try and except let your program handle them and keep running instead of crashing.DoneLockedWebFunctions, parameters and returnA function is a named recipe. Parameters are its inputs, return hands back the answer, and arrow functions are the short way to write one.DoneLockedSQLWindow functionsWindow functions add a ranking, a running total or a group total to every row without squashing the rows, using OVER, PARTITION BY and ORDER BY.DoneLockedCStructs, dots and arrowsA struct groups related values into one type. Read fields with a dot, and through a pointer with ->, so functions can change the real thing.DoneLocked
Cheatsheets
The syntax you keep looking up, one page per language.
PythonPython cheatsheetThe Python you reach for most, from printing and strings to dicts, functions, errors, files and classes, one short line at a time.11 sectionsWebWeb cheatsheetThe HTML, CSS and JavaScript you reach for most, from page structure and layout to the DOM, events and fetch.10 sectionsSQLSQL cheatsheetThe SQL you reach for most, from SELECT and WHERE to joins, groups, NULL, subqueries, window functions and transactions, one short query at a time.10 sectionsCC cheatsheetThe C you reach for most, from printf and types to arrays, strings, pointers, the heap, structs and files, one short line at a time.10 sections
Glossary
The words in lessons and error messages, in a sentence or two.
PythondictionaryA collection that maps keys to values, written {"potion": 3}. You look values up by key, not by position. Often shortened to dict.WebarrayA JavaScript list of values in order, written in square brackets. songs[0] is the first item, songs.length counts them and songs.push(x)…SQLaggregateA function that squashes many rows into one value: COUNT, SUM, AVG, MIN, MAX.CaddressThe number of a byte in memory. Every variable lives at one, and &score gives you the address of score.PythondocstringA string written as the first line inside a function to say what it does. Tools and help() show it.Webarrow functionA short way to write a JavaScript function: (a, b) => a + b. With no curly braces after =>, the value is returned without writing return.SQLclauseOne part of a SQL statement that starts with a keyword: SELECT, FROM, WHERE, GROUP BY, HAVING, ORDER BY, LIMIT. They always go in that…Carray decayWhen you pass an array to a function or use it in most expressions, it turns into a pointer to its first item. That is why a function…PythonexceptionAn error raised while a program runs, like ValueError or KeyError. If nothing catches it, the program stops and prints a traceback.WebPythonasync and awaitasync marks a function that can pause; await pauses it until a promise (or, in Python, a coroutine) is done and hands back the result.…SQLcolumnOne named piece of information that every row has, like title or price. Each column holds one type of value.Cbuffer overflowWriting past the end of an array, for example a 20-char name into a char name[8]. C does not stop you, and the extra bytes overwrite…Pythonf-stringA string with an f in front that fills in values from curly brackets: f"{name} has {hp} HP".WebattributeExtra information written inside an opening tag, as name="value". In <a href="/shop/">, href is the attribute that says where the link goes.SQLCTEA common table expression: a named result made with WITH name AS (...) at the top of a query, then used like a table below it. It breaks…CcompilerThe program that reads your C source and turns it into machine instructions. If it finds a mistake, it stops with a compile error and no…PythonindentationThe spaces at the start of a line. In Python they decide which lines belong to an if, loop or function, so they are part of the code.Webbox modelEvery element is drawn as a box of content, padding, border and margin. box-sizing: border-box makes width include the padding and border.SQLforeign keyA column that holds another table's primary key, like songs.artist_id pointing at artists.id. It is what you join on.CdereferenceFollowing a pointer to the value it points at, with . If p points at hp, then p = 70; changes hp.PythoniterableAnything a for loop can walk through one item at a time: lists, strings, dicts (their keys), range(10) and files.WebPythoncallbackA function you pass to other code so that code can call it later, like the function given to addEventListener, setTimeout or map.SQLGROUP BYSorts rows into groups that share a value and gives one result row per group, so aggregates work per group. HAVING then filters the groups.CheaderA file of declarations, pulled in with #include. #include <stdio.h> tells the compiler that printf exists and what it takes.Pythonkeyword argumentAn argument passed by name, like sorted(scores, reverse=True). It makes calls easier to read and lets you skip options that have defaults.WebCSS gridA CSS layout of rows and columns. grid-template-columns: 1fr 1fr 1fr makes three equal columns that the children fill in order.SQLindexA sorted lookup the database keeps for a column so it can find rows without reading the whole table, like the index at the back of a…CheapMemory you ask for while the program runs, with malloc, and must give back yourself with free. It lives until you free it, not until a…PythonlistAn ordered collection of values in square brackets that can change after it is made. squad = ["Ana", "Ben"], then squad[0] is "Ana".WebCSS selectorThe part of a CSS rule that picks which elements it styles: p, .card, #score, nav a. document.querySelector takes the same selectors in…SQLJOINCombines rows from two tables wherever a column matches, like each song with its artist. LEFT JOIN also keeps rows that found no match.Cmalloc and freemalloc(n) reserves n bytes on the heap and returns their address, or NULL if it cannot. free(p) gives them back. Every malloc needs…Pythonlist comprehensionA one-line way to build a list from a loop: [s 2 for s in scores if s > 10] doubles every score above 10.WebDOMThe Document Object Model: the browser's live tree of objects built from your HTML. JavaScript reads and changes the DOM, and the page…SQLnormalisationDesigning tables so each fact is stored once. Instead of typing an artist's country on every song, songs point at one artists row that…Cmemory leakHeap memory that is never freed, usually because the last pointer to it was lost. A program that leaks in a loop slowly uses up all memory.PythonmutableA value that can be changed in place, like a list or dict. Strings, numbers and tuples are immutable: their methods hand back new values…WebeventSomething that happens on the page, such as a click, a key press or text typed into a box. You react to one by adding a listener for it.SQLNULL valueSQL's marker for "unknown" or "missing". It is not 0 or empty text, any comparison with it is unknown, and you test for it with IS NULL.CNULLA pointer value that means "points at nothing". Check for it before you dereference, for example after malloc.Pythonnegative indexCounting from the end of a list or string: -1 is the last item, -2 the one before it.Webevent listenerA function the browser runs every time a certain event happens on an element. button.addEventListener("click", handleClick) adds one.SQLprimary keyA column (usually id) whose value is different for every row, so you can point at exactly one row. id INTEGER PRIMARY KEY.Cnull terminatorThe 0 byte, written '\0', that marks the end of a C string. "Neon" takes 5 bytes: four letters and the terminator.PythonNonePython's value for "nothing here". A function with no return gives back None, and so do methods like list.sort().WebflexboxA CSS layout for putting items in a row or a column. display: flex on the parent, then gap, justify-content and align-items space and…SQLqueryA question you ask the database in SQL. SELECT queries read data; other statements like INSERT and UPDATE change it.CpaddingUnused bytes the compiler puts between struct fields so each one starts at an address that suits its type. It can make a struct bigger…PythonrangeA run of whole numbers made on demand. range(5) is 0 to 4, and range(1, 11) is 1 to 10. Used to repeat a loop a set number of times.WebHTML elementOne piece of a page, written as an opening tag, some content and a closing tag. <p>Hello</p> is a paragraph element; <img> is an element…SQLrowOne record in a table: one song, one player, one order. Also called a record.CpointerA variable that holds an address. int p = &hp; makes p point at hp. Pointers are 4 bytes on this site's compiler.PythonselfThe first parameter of a method in a class. It points at the object the method was called on, so self.hp is that object's own HP.WebPythonJSONA text format for data made of objects, arrays, strings, numbers, true, false and null, like {"name": "Zara", "points": 9200}. APIs send…SQLschemaThe design of a database: which tables exist, their columns and types, and the keys that link them. CREATE TABLE statements describe it.CprototypeA one-line promise of a function's name, parameters and return type, like int twice(int n);, so code above the function's body can call it.PythonsetAn unordered collection with no duplicates. set(["gg", "gg", "lol"]) is {"gg", "lol"}, and checking x in s is fast.WebobjectIn JavaScript, a set of named values in curly braces: { name: "Ana", level: 12 }. Read a value with a dot, player.level, or with…SQLsubqueryA SELECT inside another query, in brackets. It can stand for one value, a list for IN, or a whole table.Csegmentation faultThe usual laptop crash when a program touches memory it does not own. This site reports it as memory access out of bounds.PythonsliceA run of items taken from a list or string with [start:end]. The start is included and the end is not, so "NeonFox"[:4] is "Neon".WebpromiseAn object that stands in for a value that is not ready yet, such as the result of a fetch. It later resolves with the value or rejects…SQLtableA grid of data about one kind of thing: songs, players, orders. Every row has the same columns.CsizeofGives the size of a type or variable in bytes, worked out by the compiler. sizeof(int) is 4 here; sizeof an array is its whole size in…PythontracebackThe report Python prints when a program crashes. Read it from the bottom: the last line names the error, the lines above show where it…WebspecificityThe score a selector gets for deciding the cascade: an id beats a class, and a class beats a plain element name. #nav .link beats .link,…SQLtransactionA group of changes that happen all together or not at all. BEGIN, then the changes, then COMMIT to keep them or ROLLBACK to undo them.Csource fileThe text file you write, like main.c. It is for people and the compiler; the machine never runs it directly.Pythontry and exceptA pair of blocks that catch an exception: Python runs the try block, and if a named error happens it jumps to the matching except block…Webtemplate literalA string written in backticks that can hold values: Level ${level} . Anything inside ${ } is worked out and put into the text.SQLviewA saved query with a name. CREATE VIEW top_songs AS SELECT ... lets you SELECT FROM top_songs as if it were a table, and it always…CstackThe memory where each function call keeps its local variables. It is handed out and taken back automatically as functions start and return.PythontupleLike a list, but it cannot change once made. Written with round brackets: point = (3, 4). Good for fixed pairs like a name and a score.Webthe cascadeHow the browser decides which CSS rule wins when several set the same property. More specific selectors beat less specific ones, and if…SQLwindow functionA function with OVER (...) that works out a value from a group of related rows but keeps every row, like a rank or a running total.CstructA type that groups named fields, like a player's name, hp and level. Use p.hp on a struct and pp->hp through a pointer to one.Webundefined and nullTwo JavaScript values meaning "nothing". undefined is what you get when something was never set, like a missing property; null is a…Cundefined behaviourCode the C standard makes no promise about, like reading past an array or overflowing an int. It may work, crash, or give wrong answers…
Challenges
Practice: a goal and some tests, nothing else. Warm-up, Core and Stretch.
PythonLongest win streakGiven a season of match results, find the longest run of wins in a row.Warm-upDoneWebCount the hashtagsGiven a feed of posts with hashtags, count how often each tag is used, the way a trending list or a tag cloud does.Warm-upDoneSQLFind the busiest hour at the tuck shopA week of school tuck shop sales with a time on each one. Work out which hour of the day is the busiest so the shop knows when to open a second till.Warm-upDoneCA health bar that stays in rangeApply a hit or a heal to a health bar and keep the result between 0 and the maximum, whatever the numbers.Warm-upDonePythonA chat filterHide banned words in a game chat message with stars, whatever their capital letters, and leave every other word alone.CoreDoneWebPlaylist lengthTurn seconds into the 3:05 and 1:02:05 times music apps show, then add up a whole playlist from its track lengths.CoreDoneSQLRank artists by listeners outside the UKA UK label wants to know which artists travel. Count how many different listeners outside the UK each artist reaches, not how many plays.CoreDoneCReverse a playlist in placeFlip the order of a playlist array without making a second array, by swapping from both ends towards the middle.CoreDonePythonMerge two game inventoriesTwo players pool their loot. Merge two inventory dictionaries into a new one, add up shared items and cap each stack at 99.CoreDoneLockedWebBasket total with discount codesWork out what an online shop charges: item prices times quantities, delivery, and three kinds of discount code.CoreDoneLockedSQLFind games bought and never playedMatch a launcher's purchases against its play sessions to find every game someone paid for and has not opened once.CoreDoneLockedCTurn a clock time into minutesParse a time like "12:45" into minutes after midnight, character by character, and reject anything that is not a real time.CoreDoneLockedPythonA leaderboard of best scoresTurn a log of every round played into a top-N leaderboard: one row per player, their best score, ties in name order.CoreDoneLockedWebLeaderboard ranks with tiesSort a game's players by points and give each one a rank, where players on the same points share a rank, like a real leaderboard.CoreDoneLockedSQLFind timetable clashes for Year 12Year 12 chose their option classes. Join the timetable to itself to find every student who is meant to be in two rooms at once.CoreDoneLockedCThe last five scoresKeep only the most recent five match scores in a fixed array that wraps around, the ring buffer behind every "recent games" panel.CoreDoneLockedPythonBuild a football league tableRead match results like "Lions 2-1 Tigers", award points, and sort the table by points, goal difference and name.StretchDoneLockedWebA chat filterClean up a game's chat log: drop muted users, mask banned words with stars, and hide copy-paste spam.StretchDoneLockedSQLSuggest accounts to followThe "people you may know" list on a social app: accounts followed by the people you follow, ranked by how many of them follow it.StretchDoneLockedCFind a player by ID, fastSearch a sorted array of 100,000 player IDs with binary search, halving the range each step, and prove it with a step counter.StretchDoneLockedPythonFind timetable clashesGiven a week of clubs and lessons with start and end times, find every pair that overlaps on the same day.StretchDoneLockedWebA chat rate limiterStop spam in a chat app by letting each user send only a few messages in any rolling time window, using timestamps.StretchDoneLockedSQLBuild the league table from match resultsTurn a season of football scores into a proper league table: played, won, drawn, lost, goals for and against, goal difference and points, as a view.StretchDoneLockedCCompress a level rowSquash a row of a tile map like "####....##" into "4#4.2#" with run-length encoding, writing into a buffer the caller gives you.StretchDoneLocked
Examples
Practice: bigger programs to read, run and open in the playground.
PythonA loot tableHow games pick a random drop: weighted chances, a seeded random generator so the results repeat, and a tally of a thousand drops.DoneWebA reaction-time testerA one-file page that waits a random time, turns green, and measures how fast you click. Timers, events and a little state.DoneSQLAn artist report for a streaming appOne query that builds the monthly report a streaming app sends its artists: plays, listeners, skip rate and their most played song.DoneCA hex dump of a structPrint every byte of a game save struct in hex and see the fields, the little-endian ints and the padding bytes nobody asked for.DonePythonA sales report from a CSVRead a school tuck shop's sales from CSV text with the csv module, skip bad rows, then print totals, a best seller and a text bar chart.DoneLockedWebA habit-streak trackerHow streak apps work: turn a list of check-in dates into current and best streaks per habit, with real date maths.DoneLockedSQLA creator dashboard for video channelsThe numbers a video platform shows its creators: views, watch hours, how much of each video people actually watch, comments, subscribers and the top video.DoneLockedCAn array that growsBuild a list of chat messages that grows with realloc, doubling its capacity when full, and watch the size, the capacity and the address change.DoneLockedPythonA tiny text adventure engineRooms in a dictionary, an inventory list and a command parser, driven by a fixed list of commands so you can watch a whole playthrough.DoneLockedWebWhack-a-mole with a timerA complete little DOM game: a grid of holes, a mole that hops around, a score, a 20-second countdown and a high score.DoneLockedSQLA month-by-month sales reportSix months of an online shop in one report: revenue per month, a running total for the year, the change on last month and the best-selling category.DoneLockedCA tiny stack calculatorEvaluate sums like "3 4 + 2 *" with a stack, the way old calculators and many virtual machines work, printing the stack at every step.DoneLocked
Nothing here for that course yet.