Conditional loop based on randomized correct key presses

It is often worth putting in (temporary) debugging code, like:

print(csplusfearloop_prac.thisN)
print(csplusfearloop_prac.nTotal)
print(number_correct/(csplusfearloop_prac.nTotal + 1))

Does .nTotal mean what you think it means? Those attributes are listed here:

https://www.psychopy.org/api/data.html

i.e. I don’t think .thisN (zero-based) could ever equal .nTotal (one-based I think). But even if it did, your code would be asking “if this is the last trial of this loop, then consider ending the loop”.

i.e. perhaps you need to express in prose what you want to do, and then we can suggest what code could implement that.

Also, please do this to format your code properly (it helps us to see the indenting, and is what I did by editing your initial post)):