VEX IQ Robot Brain Gen 2 -- Memory Allocation Error

For Python, there’s no fixed formula. There a maximum size the source can be (your code was at about 75% of that limit) but then the VM has to convert the source to bytecode and that’s far more dependent on the number of variables, functions etc. and is not easy to calculate. C code is easier to handle in this respect.

The limit is determined by available RAM, so no, not really possible. Your code would compile on an EXP brain which has approximately 5 x available memory for user programs as compared to IQ gen 2.