[Tutor] roman to arabic

bob gailer bgailer at gmail.com
Mon Feb 27 05:23:02 CET 2012

On 2/26/2012 6:29 PM, Sukhpreet Sdhu wrote:
> Hi
> I just wrote python code to convert roman to arabic numerals
[snip] Yuk what a  mess.

May I suggest you start with a much simpler program, which is to take a 
roman number between 1 and 3 (just i's) and convert that.

First describe how you'd convert the number by hand. Then convert that 
process to Python.

Test the program. Fix any problems. Report back to us success or a 
problem you don't know how to address. Tell us exactly what went wrong. 
(e.g. I entered iii expecting 3 and got 17 or if you get a traceback 
post it. For example when I run your program I get:

Traceback (  File "<interactive input>", line 12
     if roman_numeric == ("M" or "D" or "L" or "C" or "L" or "X" or "V" 
or "I"):
IndentationError: unindent does not match any outer indentation level

Then add v (now the number is between 1 and 8).

You will come up with a completely different program! And it will be the 
correct one.

Also provide meaningful prompts.

print "Please enter command"

If I was running your program and saw that I'd have to give up since I 
have no idea what is expected.

print "Please enter command - r for roman-arabic"

would be much better.

Bob Gailer
Chapel Hill NC

More information about the Tutor mailing list