Block code precision translation explanation

what is going on with the vexcode translation of printing to the brain screen in block code??? I know my way around python pretty well, but I’ve never seen this before.

brain.screen.print(intake.temperature(PERCENT), precision=6 if vexcode_brain_precision is None else vexcode_brain_precision)

I’m trying to make a brain simulator, and I’m almost done, but this is one of the last things that I am struggling with. My function right now looks like this, but its only taking the precision=6 part, and not the if statement.

def print(self, *text, sep=" ", precision=2):
        printme = ''
        for arg in text:
            if (type(arg) is float) or (type(arg) is int):
                printme += str(f"{arg:.{precision}f}")
            else:
                printme += arg
            printme += sep
        printme = printme.rstrip(sep)

How do i have my code accept this, or can I take a peek into how the vex brain does it?

I’m pretty sure it’s just a ternary. I don’t know why your print function wouldn’t work with that call, since ternaries have higher precedence than assignment. If you call it when vexcode_brain_precision is None, then it should use 6. How are you testing it, and what is the error?

well I got it all figured out. It was just a mistake on my end with setting vexcode_brain_precision wrong, but I had never heard of a ternary before, so thank you :slight_smile:

1 Like