regex test passes, but the program doesn't quite work

TypeError: cannot concatenate str and NoneType objects (line 111) -- I
think you need to change the position of your question mark in your
opening brace regex so .group("code") can be the empty string
regex test passes, code runs, but not well

the debugging output looks way different than it ought to
added two lines that failed and one that worked from a real test