I am trying to populate fields with centred Easting/ Northing coordinates from a field of British National Grid grid references. I want to take different digits from the grid reference depending on its number of characters (precision). Without going into the details of BNG grid references too much, an example expression to take an Easting coordinate for me looks like this:
int(str(!Easting_1!)+str(!Grid_ref![2:7]))
If I enter this, or a slightly modified version for a different length grid reference, directly as the field calculator expression, it works fine. However, when I try to include a bunch of slightly modified versions of the above as if/else statements in the Code Block, I get an invalid syntax error:

I'm not sure what is going on as I am copying and pasting code from if/else statements that work fine for me elsewhere, just replacing the return value with 'int(str(!Easting_1!)+str(!Grid_ref![X:X]+"X"))', which is an expression that works fine when I use it to calculate a field directly, without the Code Block.
Any help much appreciated!