3 Eã\ ã@s‚dZdZdZdZdZddlZGdd„deƒZGd d „d eƒZGd d „d eƒZ Gd d„deƒZ d;Z d)d*„Z ej d+ejƒZd,d-„ZdS)W|S)z convert integer to Roman numeralriˆz%number out of range (must be 1..4999)zdecimals can not be convertedÚ)rÚintr ÚromanNumeralMap)ÚnÚresultÚnumeralÚintegerrrrÚtoRoman(s  r,a8 ^ # beginning of string M{0,4} # thousands - 0 to 4 M's (CM|CD|D?C{0,3}) # hundreds - 900 (CM), 400 (CD), 0-300 (0 to 3 C's), # or 500-800 (D, followed by 0 to 3 C's) (XC|XL|L?X{0,3}) # tens - 90 (XC), 40 (XL), 0-30 (0 to 3 X's), # or 50-80 (L, followed by 0 to 3 X's) (IX|IV|V?I{0,3}) # ones - 9 (IX), 4 (IV), 0-3 (0 to 3 I's), # or 5-8 (V, followed by 0 to 3 I's) $ # end of string cCsr|s tdƒ‚tj|ƒs"td|ƒ‚d}d}xBtD]:\}}x0|||t|ƒ…|krh||7}|t|ƒ7}q:Wq0W|S)z convert Roman numeral to integerzInput can not be blankzInvalid Roman numeral: %sr)r ÚromanNumeralPatternÚsearchr'Úlen)Úsr)Úindexr*r+rrrÚ fromRomanCs  r2©r r ©r r©rr©rr©rr©rr©rr©rr©rr©rr©rr ©r!r"©r#r$) r3r4r5r6r7r8r9r:r;r<r=r>r?)Ú__doc__Ú __author__Ú __version__Ú__date__Ú __copyright__ÚreÚ Exceptionrrr r r'r,ÚcompileÚVERBOSEr-r2rrrrÚs4