Introduction to Python for Simple Behavioral Experimentation

Undergraduate course, 2.14.0.35, Golm, 15.10.2025 – 04.02.2026

This course introduces beginners to Python programming and the basics of creating simple behavioral experiments used in cognitive science, such as reaction time, decision-making, and memory tasks.


Contents


Course Description

Part 1: Intro to Python (8 weeks)

This first part introduces beginners to the fundamentals of Python programming. Students will learn core programming concepts and tools used for data handling and basic scripting.

Key Topics:

  • Getting started with Python (syntax, variables, data types)
  • Control structures (loops, conditionals, functions)
  • Working with data (lists, dictionaries, NumPy, and pandas basics)
  • Introduction to Psychopy

Outcome:
By the end of Part 1, students will be comfortable writing and running basic Python programs.

Part 2: Building Behavioral Experiments in Python (6 weeks)

This second part builds on the programming foundation and focuses on creating, running, and analyzing simple behavioral experiments. Students will learn to design experiments involving reaction time, decision-making, and memory.

Key Topics:

  • Designing experiments using PsychoPy
  • Programming reaction time and decision-making tasks
  • Collecting and storing participant data
  • Basic data analysis and visualization in Python
  • Debugging

Outcome:
By the end of Part 2, students will be able to create and analyze their own behavioral experiments relevant to cognitive science research.


Weekly Schedule (Weeks 1-15)

WeekDateTopicResourcesHelpful Links
1Oct 15Intro to Programming, Python, and Setup (Ch. 2, 3)Slides, NotebookInstallation Guide
2Oct 22Statements, Expressions (Ch. 4), Functions (Ch. 5)Slides, Variables, Functions 
3Oct 29I/O (Ch. 7), Conditions, Branching (Ch. 8)Slides, IO, Conditions 
4Nov 5Sequences (Lists) (Ch. 10), Loops (While) (Ch. 11), Style (Ch. 6)Slides_lists, Slides_while, Lists, While 
5Nov 12Loops (For) (Ch. 11), Dictionaries (Ch. 16), File I/O (Ch. 13)Slides_for, Slides_dict, For, Dict 
6Nov 19 23CSV, Numpy, PandasSlides_Pandas, Dataset, Pandas, Misc.Lecture Video
7Nov 26Intro to PsychoPy, Setting upSlides_Psychopy, Code folderVideo: How to setup Vscode or Psychopy
8Dec 3Display and Stimulus PresentationSolutions and lecture folder, specific files: Dialog Box notebook, Dialog box exercises, Windows options, Win. exercises 
9Dec 10Events and loggingLecture Folder 
10Dec 17stimuli - input, shuffle, Output, debugLecture FolderDebugging tutorial
11Jan 7Analysis, VisualisationLecture FolderMatplotlib installation, Lecture Video
12Jan 14Working on Project  
13Jan 21Working on Project  
14Jan 28Working on Project  
15Feb 4Project Presentations  

Course Textbooks

Main Text:
Cafiero, Clayton. An Introduction to Programming and Computer Science with Python, 2nd Edition, 2023–2025. | ISBN: 979-8-9887092-1-3

Additional Suggested Readings:
Bonaretti, Serena. Learn Python with Jupyter
Downey, Allen B. Think Python

Psychopy: Psychopy official website


Final Project

Goal: Create and run a behavioral experiment using Python and PsychoPy in a group of 2 people.

  • Students must select their experiments from these two lists (psytoolkit list, pavlovia) online.

  • A sheet will be circulated sometime after we introduce PsychoPy and behavioral experiments (around the end of November or the start of December). Update: Students must inform about their group and get their projects confirmed by 11. December.

  • You are also welcome to suggest experiments outside the provided list and discuss them. Please note that each group should select a different experiment.

Requirements

  • Group size: Each project should be completed in groups of two students.

  • Participant Data Collection: Collect and analyze data from approximately 8-10 participants.

  • Submission: Submit your complete & well-documented code, analysis files, and a brief write-up (1-2 pages) explaining the problem statement, the experiment, the analysis, work distribution, etc., by the end of the day on February 1.

  • Deliver a Presentation following the guidelines - see Presentation Guidelines, and submit your presentations files.

Presentation Guidelines

During the final presentation, each group should deliver a 9-minute presentation (+ 2 minutes for Q&A) that includes the following sections atleast:

  1. Introduction
    • Introduce the goal or research question your experiment addresses.
  2. Experiment Design and Demonstration
    • Outline your experimental structure (tasks, stimuli, conditions, and responses).
    • Explain how participants interact with the task.
    • Describe any challenges faced or design decisions made during development.
    • Run a short live demonstration of your experiment.
  3. Data and Analysis
    • Present a summary of the data collected (e.g., reaction times, accuracy).
    • Include simple visualizations (plots, tables) created with Python.
    • Provide a brief interpretation of what the results indicate.
  4. Reflection
    • Explain how you divided the tasks within the team and who contributed to which parts.
    • Discuss what worked well, what was challenging, and what you learned.
    • Suggest possible improvements or extensions for the future.

Final Presentation Date: February 4, 2026

Grading

The final project is assessed on a Pass/Fail basis. To pass, students must complete the Final Project and fulfill all the Requirements


LLM policy

Adapted from Prof. Mausam’s guidelines

It is acceptable to seek help from an LLM/Conversationsal Chat agents. But you cannot copy any piece of code or document from an LLM. For example, interact with an LLM to get intuition about the project, critique ideas, and brainstorm. Also, use LLM to learn syntax for a language, get help with debugging. But do NOT use it to write code that you copy/paste in for your final project. Instead, write your own code yourselves.


Office Hours

  • Time: Wednesday 16:00–17:00 (by appointment)
  • Location: bldg. 14, room 4.10, Golm