954,541 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

***Help! Code not working out-Roman Numeral Converter

This is a project I'm working on for a class. I'm pretty new to CS and python...and I found that I am totally lost. I'm suppose to write a program to convert Roman numerals to arabic numbers. It is also suppose to handle invalid input.

Here is what I have so far:

def roman_converter():

R=str.upper(raw_input("Enter a Roman numeral to convert to Arabic: "))

d={'I':1, 'V':5, 'X':10, 'L':50, 'C':100, 'D':500, 'M':1000}

s=0
for c in range(len(R)):
while R[0]

tech12
Newbie Poster
1 post since Apr 2009
Reputation Points: 10
Solved Threads: 0
 

Well, there's two types of validation... you'll need to first verify that the numerals are in the right order, ie, you can't have IC or something, but you could have XC, or IX, but not VX or IL, etc. That's one validation.

The other validation that you would need is to make sure that ONLY characters used for roman numerals are input. If you're just working with I,V,X,L,C,D,and M, then any other character is invalid.

Does that make sense?

alc6379
Cookie... That's it
Team Colleague
2,820 posts since Dec 2003
Reputation Points: 186
Solved Threads: 147
 

You might start with code tags (use the "#" icon) and then explain what the program you posted does, as it doesn't appear to make sense. Once you reach this line
while R[0]

woooee
Nearly a Posting Maven
2,454 posts since Dec 2006
Reputation Points: 777
Solved Threads: 714
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You