Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: markeganfuller/londondojo-team4-roman-numeral
base: f29a7866f2
...
head fork: markeganfuller/londondojo-team4-roman-numeral
compare: 06f98482ce
  • 2 commits
  • 1 file changed
  • 0 commit comments
  • 1 contributor
Showing with 18 additions and 1 deletion.
  1. +18 −1 roman.py
View
19 roman.py
@@ -1,12 +1,27 @@
+import sys
+
+
+"""
+Program to add together 2 roman numerals
+without using integers.
+
+2012 Python Dojo
+"""
CHARS = ['I','V','X','L','C','D','M']
+""" Characters by order """
+
def rank(roman_char):
+ """ Return the rank of a roman char """
return CHARS.index(roman_char)
def prep_numeral(numeral):
+ """
+ Prepare a numeral for simple concatenation, removing all subtractions
+ """
out = []
n = 0
while n < len(numeral):
@@ -29,10 +44,12 @@ def prep_numeral(numeral):
def sort_numeral(numeral):
+ """ Sort numerals according to rank. """
return sorted(numeral, key=rank, reverse=True)
def compress_numeral(numeral):
+ """ Compress a crudely constructed numeral """
numeral = ''.join(numeral)
while True:
l = len(numeral)
@@ -55,6 +72,7 @@ def compress_numeral(numeral):
def add_numeral(n1, n2):
+ """ Add 2 numerals """
n1 = prep_numeral(n1)
n2 = prep_numeral(n2)
@@ -65,7 +83,6 @@ def add_numeral(n1, n2):
if __name__ == '__main__':
- import sys
n1, n2 = sys.argv[1:]
print 'in:', n1, n2
print 'out', add_numeral(n1, n2)

No commit comments for this range

Something went wrong with that request. Please try again.