# [Tutor] Roman Numeral to Digital

Bob Gailer bgailer at alum.rpi.edu
Thu Mar 8 15:12:58 CET 2007

```Kent Johnson wrote:
> Hi Alan,
>
> I am forwarding your question to tutor at python.org which is the correct
> address for the list. tutor-owner at python.org sends questions to the
> *maintainers* of the list, not the list itself.
>
> Kent
>
> Alan Gilfoy wrote:
>
>> I am learning how to program in python as a major component of my
>> school's senior project, and my most recent assignment was to write a
>> program that converts Roman numerals to digital (base-10 Arabic numerals).
>>
>> Now, I was told I have to write the program myself, but I was told I was
>> allowed to ask for hints. :)
>>
>> As of right now, I've written a user interface (after all, here that's a
>> simple loop-and-prompt setup leading to print statements), but I have
>> "dummy code" in the place where the conversion code needs to be.
>>
>> I want to create two separate functions:
>>
>> def.toRoman(digital_input)
>>     print "Digital - to - Roman conversion (dummy code)"
>>     roman_result = "XXX"
>>     return roman_result
>>
>> def.toDigital(roman_input)
>>     print "Roman - to - digital conversion (dummy code)"
>>     digital_result = 30
>>     return digital_result
>>
>> I'm going to set each of those two "inputs" by a prompt asking for what
>> the program user wants to work with.
>>
>> #Such as:
>> digital_input = int(raw_input("What digital (base-10) number do you wish
>> to convert to Roman numerals?))
>>
>> I'm not sure how I would program Python to run the actual conversions.
>>
>> PS: I'm familiar with Roman numerals, and I know how to do the
>> conversions manually.
>>
Step 1:  write down the steps you use "manually"
Step 2:  for each step ask "how do I do this in Python:

Example:
I initialize the digital value to 0
digital_result = 0

I examine each roman numeral character in turn starting at the left (or
right?):
for rc in roman_input:

I lookup the character's decimal value
(note there are several ways to do this in Python - the "best" is a
dictionary), an if elif else statement, ....

I add it to the digital_result

etc.

Hope that gets you started. Write all the manual steps. Make sure each
is one simple operation. Walk thru the steps to verify that you have
them correct.

--
Bob Gailer
510-978-4454

```