# Python: Super-Simple Roman Numeral -\> Arabic

**URL:** <https://forum.kirupa.com/t/python-super-simple-roman-numeral-arabic/202028>\
**Category:** open source\
**Created:** [September 27, 2006, 2:45am UTC](https://forum.kirupa.com/t/python-super-simple-roman-numeral-arabic/202028 "2006-09-27T02:45:03Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jeff\_Wheeler](https://avatars.discourse-cdn.com/v4/letter/j/59ef9b/32.png) [@Jeff\_Wheeler](https://forum.kirupa.com/u/Jeff_Wheeler)\
**Post date:** [September 27, 2006, 2:45am UTC](https://forum.kirupa.com/t/python-super-simple-roman-numeral-arabic/202028/1 "2006-09-27T02:45:03Z")

</div>

I just wrote this… it’s a very simple way to solve them. Yes, I know everybody’s done this… but mine takes, well, uh, no code. 😃

```auto
def roman2arabic(value):
    total = 0
    values = {
        'I': 1,
        'V': 5,
        'X': 10,
        'L': 50,
        'C': 100,
        'D': 500,
        'M': 1000
    }
    
    prevValue = 0
    for char in value:
        if values[char] > prevValue:
            total -= prevValue
        else:
            total += prevValue
        prevValue = values[char]
    total += prevValue
    
    return total

```

Just pass it a string… 🙂
