fork download
  1. nums = [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1]
  2. roman = ['M', 'CM', 'D', 'CD','C', 'XC','L','XL','X','IX','V','IV','I']
  3.  
  4. def from_roman_numeral(roman_numeral):
  5. result = 0
  6. if roman_numeral in roman:
  7. result += nums[roman.index(roman_numeral)]
  8. else:
  9. arr = list(roman_numeral)
  10. for i in range(0, len(arr) - 1):
  11. if arr[i] in roman:
  12. if arr[i] >= arr[i + 1]:
  13. result += nums[roman.index(arr[i])]
  14. elif arr[i] <= arr[i + 1]:
  15. result -= nums[roman.index(arr[i])]
  16. print(result)
  17. return result
Success #stdin #stdout 0.02s 7276KB
stdin
Standard input is empty
stdout
Standard output is empty