Playing a sound alternating left and right channel

I’ve made this code based on Pyo and this works perfectly if I run it in the IDE i.e. Pycharm. But now i want to translate it to a Psychopy experiment. If i copy-paste the code, I can make it run if I make a single trial (import part in Before experiment tab, rest of code in Begin routine tab) but after that I get stuck. Adding text interferes with the code, trying to use the sound stimulus is not working. I’ll keep trying but I just want the sound to be simply either left or right based on the choice of a list. I’ve tried going through a lot of previous posts and also on other sites but I have not enough progamming knowledge to understand that yet and am wondering if there is not a simple solution like the one im using where it chooses either 0 or 1 for the output channel. Thanks in advance!

import sys, time
from pyo import *
import random
import time
s = Server().boot()             # boot the server for pyo
s.start()                       # to automatically start the sounds
n = Sine(freq=40)               # sine frequency to make the right tapping stimulus

choices_list = [                # a list of the 4 combinations possible for the stimuli, 3x for 12 trials
   {"channel": 0, "amplitude": 0.3},
   {"channel": 1, "amplitude": 0.7},
   {"channel": 0, "amplitude": 0.7},
   {"channel": 1, "amplitude": 0.3},
   {"channel": 0, "amplitude": 0.3},
   {"channel": 1, "amplitude": 0.7},
   {"channel": 0, "amplitude": 0.7},
   {"channel": 1, "amplitude": 0.3},
   {"channel": 0, "amplitude": 0.3},
   {"channel": 1, "amplitude": 0.7},
   {"channel": 0, "amplitude": 0.7},
   {"channel": 1, "amplitude": 0.3},
     ]
for x in range(12):                         # creating a for loop to cycle randomly through the stimuli
   selected_combination = choices_list.pop(random.randrange(len(choices_list)))    # popping each used item from the list to prevent it from returning too often
   print(selected_combination)             # prints the chosen combination

   n_channel_selector = selected_combination["channel"]       # takes the channel from the selected combination

   s.amp = selected_combination["amplitude"]                  # sets the amplitude to that from the selected combination
   print(s.amp)                                               # prints the chosen amplitude

   n.out(n_channel_selector)                                  # outputs the sine wave, from the chosen channel
   time.sleep(0.1)                                            # sleep to create the duration of the stimulus (tap)

   n.stop()                                                   # stop the wave
   time.sleep(2)