Class 3 — Builder → Coder
Part I
Open PsychoPy’s Coder view for the first time to read the Python that Builder has been generating for you all along, make some small, safe edits directly in code, and write a short script of your own from scratch.
Every time you’ve clicked “Run” in Builder, PsychoPy has quietly written a Python script behind the scenes. Today you finally open it. Most of class is spent reading that generated code, not writing new code — you’ll go on a guided scavenger hunt through a Builder-generated script, finding the trial loop and the conditional that scores a correct response, and make some small edits directly in Coder. Then the closing exercise flips that: you’ll build a short, original Python script of your own, completely from scratch.
Reading due: Think Python ch. 5, 7 · Due the night before (Mon 9/21, 11:59 PM): HW1
What you’ll be able to do
- Trace how an
if/elif/elseconditional decides between two outcomes, and how aforloop repeats a block of code, reinforced through a Colab warm-up. - Open PsychoPy’s Coder view on an existing Builder-generated experiment and locate the auto-generated
.pyfile. - Identify the
forloop in the generated script that corresponds to the trial loop you built visually in Builder, and connect it back to the conditions spreadsheet from Class 2. - Identify at least one
ifstatement in the generated code (e.g., the correct-answer check) and explain what condition it’s testing. - Make some small, non-breaking edits directly in Coder (e.g., change the instructions screen’s hardcoded text color) and confirm the experiment still runs.
- Write a short, original Python script — a list of stimuli, a
forloop,input(), and anif/elsecheck — from scratch in Coder, applying the same patterns practiced in today’s warm-up to a new task.