Skip to content

Latest commit

 

History

History
29 lines (25 loc) · 602 Bytes

File metadata and controls

29 lines (25 loc) · 602 Bytes

What Did I Learn?

In this challenge I learned more about logic:

  1. We start the problem by creating a dictionary:
translations = {
    "I": 1,
    "V": 5,
    "X": 10,
    "L": 50,
    "C": 100,
    "D": 500,
    "M": 1000
}
  1. Then we handle exceptions:
s = s.replace("IV", "IIII").replace("IX", "VIIII")
s = s.replace("XL", "XXXX").replace("XC", "LXXXX")
s = s.replace("CD", "CCCC").replace("CM", "DCCCC")
  1. And finally, we exchange the key for the value in the dictionary and add it to a variable:
for char in s:
    number += translations[char]