# Creating blocks of trials with equal numbers of two image types

**URL:** <https://discourse.psychopy.org/t/creating-blocks-of-trials-with-equal-numbers-of-two-image-types/10268>\
**Category:** Builder\
**Created:** [December 12, 2019, 7:39am UTC](https://discourse.psychopy.org/t/creating-blocks-of-trials-with-equal-numbers-of-two-image-types/10268 "2019-12-12T07:39:22Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![c\_b](https://avatars.discourse-cdn.com/v4/letter/c/d78d45/32.png) [@c\_b](https://discourse.psychopy.org/u/c_b)\
**Post date:** [December 12, 2019, 7:39am UTC](https://discourse.psychopy.org/t/creating-blocks-of-trials-with-equal-numbers-of-two-image-types/10268/1 "2019-12-12T07:39:22Z")

</div>

Hi,

I am very new to coding, and am trying to write an experiment that shows two classes of stimuli (Stimulus A and Stimulus B) for 30 seconds each, with a 30 second blank baseline period between to be used for an imaging experiment. So A - BLANK- B- BLANK - B - BLANK - A BLANK - B etc

At the moment, I have Psychopy pulling 20 random images from an excel spreadsheet and presenting them in a random order for each block of trials (based on this video [https://www.youtube.com/watch?v=r0z6lGhuaEY](https://www.youtube.com/watch?v=r0z6lGhuaEY)), and saving a key press after each stimulus. This is working fine, but I don’t have a lot of control over what images are presented and when.

What I would like to achieve is to have equal numbers of A and B presented in each block, in a random order, and not having them repeated in other blocks for the same participant. Each participant would be presented with 100 stimuli in total, split into 5 groups of 20 images, and each group of 20 will have 10 images from category A and 10 from category B.

I’m pretty sure I need some sort of loop in the code to make a 2 alternative forced choice type design, but I’m not sure how to put it together. Any help or recommended resources would be much appreciated. Thank you!
