Turn Python functions into apps with inputs and outputs: a greeter, a calculator with several inputs, and a quiz built from a list of questions, in an in-browser stand-in for Gradio that runs the same code as the real thing.
Each lesson works two ways. Students can work through the online tutorial at their own pace (it checks their answers and saves their progress in their browser), or you can teach it to the whole class from the slides, then send students into the tutorial for the Modify and Make steps.
Every lesson guide has plain-language notes, the answers to every check, a solution for every task, and slides and a worksheet for Waypoints Prepare. These guide pages are not linked from student pages, but they are not secret either: keep printed Teacher editions for answers you do not want students to find.
Whole-course cheat sheet: Open to print (every command, grouped by unit: a handout for the final challenge)
A function plus inputs and outputs makes an app; more inputs mean more parameters, in the same order.
Gradio turns a Python function into an app. gr.Interface(fn=greet, inputs=[...], outputs=[...]).launch() draws one box for each input, a Submit button, and one box for each output. On Submit, Gradio calls the function with the inputs' values in order (the first input to the first parameter), and puts each returned value in an output, in order. A function gives two outputs by returning two values: return total, summary.
Each kind of input gives a different kind of value: a Textbox gives text, a Slider or Number a number (possibly 2.0), a Checkbox True or False, a Dropdown or Radio the chosen text.
The playground runs a small stand-in for Gradio so it works in the browser. The same file runs unchanged in real Gradio: pip install gradio, then python app.py, and open http://127.0.0.1:7860. A teacher can host an app as a Hugging Face Space (accounts need age 13+).
print before any app exists.A vending machine: the buttons are inputs, the machinery is the function, the tray is the output. It breaks because a vending machine's buttons are labelled; Gradio matches inputs to parameters by position, not by label, so the order must match.
greet() would call it now.int() drops the .0.Cheat sheet: Open to print (A4, with a picture of what each command draws) · Markdown
Questions as data, an input made for each one, and a function that marks the answers.
Questions as data. Each question is a dictionary ({"q": ..., "choices": [...], "answer": ...}), and the questions are a list. One loop makes a gr.Radio input for each question; the marking function compares each answer with its question's answer, counts a score and builds feedback. Adding a question means adding data, plus one more parameter for its answer.
Objects (the optional lesson). A class, Question, bundles each question's data with the code that uses it: check(guess) and feedback(guess) are methods, and inside them self.answer is that question's own answer. The marking function just asks each question to check itself.
A stack of question cards with the answer on the back: the loop deals each card as a question, and marking flips each one over. It breaks because the computer compares exactly: "Carbon Dioxide" is not "Carbon dioxide", so answers must match the choices character for character.
None does.def mark(*answers): takes any number as a list (a stretch).Cheat sheet: Open to print (A4, with a picture of what each command draws) · Markdown