def numeral(n):
    numerals = (n//1000) * "M"
    numerals += _numeral(((n%500)//100, (n%1000)//500), ("C", "D", "M"))
    numerals += _numeral(((n%50)//10, (n%100)//50), ("X", "L", "C"))
    numerals += _numeral(((n%5), (n%10)//5), ("I", "V", "X"))
    return numerals


def _numeral(nums, letters):
    i, v, x = letters
    if nums[1] == 1:
        return i + x if nums[0] == 4 else v + nums[0] * i
    else:
        return i + v if nums[0] == 4 else nums[0] * i

@@ -69,23 +69,8 @@
 ral(
-((n%25500)//100, 
 (n%251
@@ -79,15 +79,13 @@
 0)//
-5
+1
 00
-)
 , 
-(
 %22C%22,
@@ -94,17 +94,16 @@
 D%22, %22M%22)
-)
 %0A    num
@@ -124,21 +124,8 @@
 ral(
-((n%2550)//10, 
 (n%251
@@ -133,14 +133,12 @@
 0)//
-50)
+10
 , 
-(
 %22X%22,
@@ -147,17 +147,16 @@
 L%22, %22C%22)
-)
 %0A    num
@@ -177,29 +177,14 @@
 ral(
-((n%255), (n%2510)//5)
+n%2510
 , 
-(
 %22I%22,
@@ -193,17 +193,16 @@
 V%22, %22X%22)
-)
 %0A    ret
@@ -236,42 +236,45 @@
 (num
-s
 , 
-letters
+i, v, x
 ):%0A    
-i, v, x = letters
+n, m = divmod(num, 5)
 %0A   
@@ -282,14 +282,8 @@
 if n
-ums%5B1%5D
  == 
@@ -305,31 +305,25 @@
 rn i + x if 
-nums%5B0%5D
+m
  == 4 else v
@@ -325,23 +325,17 @@
 lse v + 
-nums%5B0%5D
+m
  * i%0A   
@@ -365,23 +365,17 @@
  + v if 
-nums%5B0%5D
+m
  == 4 el
@@ -381,15 +381,9 @@
 lse 
-nums%5B0%5D
+m
  * i

Simplify _numeral helper function