summaryrefslogtreecommitdiff
path: root/examples/romanNumerals.py
diff options
context:
space:
mode:
Diffstat (limited to 'examples/romanNumerals.py')
-rw-r--r--examples/romanNumerals.py14
1 files changed, 4 insertions, 10 deletions
diff --git a/examples/romanNumerals.py b/examples/romanNumerals.py
index 27361f0..536fbb0 100644
--- a/examples/romanNumerals.py
+++ b/examples/romanNumerals.py
@@ -7,7 +7,7 @@ from pyparsing import *
def romanNumeralLiteral(numeralString, value):
return Literal(numeralString).setParseAction(replaceWith(value))
-
+
one = romanNumeralLiteral("I",1)
four = romanNumeralLiteral("IV",4)
five = romanNumeralLiteral("V",5)
@@ -22,8 +22,8 @@ fivehundred = romanNumeralLiteral("D",500)
ninehundred = romanNumeralLiteral("CM",900)
onethousand = romanNumeralLiteral("M",1000)
-numeral = ( onethousand | ninehundred | fivehundred | fourhundred |
- onehundred | ninety | fifty | forty | ten | nine | five |
+numeral = ( onethousand | ninehundred | fivehundred | fourhundred |
+ onehundred | ninety | fifty | forty | ten | nine | five |
four | one ).leaveWhitespace()
romanNumeral = OneOrMore(numeral).setParseAction( lambda s,l,t : sum(t) )
@@ -34,7 +34,7 @@ def makeRomanNumeral(n):
n -= limit
s += c
return n,s
-
+
ret = ""
while n >= 1000: n,ret = addDigit(n,1000,"M",ret)
while n >= 900: n,ret = addDigit(n, 900,"CM",ret)
@@ -66,9 +66,3 @@ test("XIV")
test("XIX")
test("MCMLXXX")
test("MMVI")
-
-
-
-
-
-