Roman to Integer

class py_solution:
    def roman_to_int(self, s):
        rom_val = {'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000}
        int_val = 0
        for i in range(len(s)):
            if i > 0 and rom_val[s[i]] > rom_val[s[i - 1]]:
                int_val += rom_val[s[i]] - 2 * rom_val[s[i - 1]]
            else:
                int_val += rom_val[s[i]]
        return int_val

print(py_solution().roman_to_int('MMMCMLXXXVI'))
print(py_solution().roman_to_int('MMMM'))
print(py_solution().roman_to_int('C'))


3.5
4
Luaan 110 points

                                    Symbol       Value
I             1
V             5
X             10
L             50
C             100
D             500
M             1000

3.5 (4 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
convert int to roman numeral roman to integer converting code int to roman converter roman to integer in py integer to roman convertor converting numbers to roman numerals in python how to convert roman to integer in python 13. roman to integer python roman to int in python how to convert roman to integer converting from roman numbers to numbers ion python roman to integer online integer to roman online how to convert roman number to integer code to convert roman numerals to numbers python convert integer to roman number roman numeral to integer pyhtpon roman numeral to integer convert roman numerals to int roman to integer calculator roman to integer converter write a python program to convert a roman numeral to an integer. how to conevert numbers to roman numerals python roman to int Roman to Integer roman numerals to integer Roman Number to Integer integer to roman converter online roman to decimal converting decimal to roman number roman numbers to integers roman numerals to decimal python roman numeral to decimal python roman to integer solution python roman number to decimal in python 13. Roman to Integer 6. Roman Number to Integer decimal number to roman number roman to numeric python covert roman number to number in python integer to roman conversion integer to roman converter how to change roman numerals to numbers in python convert int to roman numneral converting integer to roman how to convert numbers into roman numerals in python roman to integer in python decimal to roman converter how to convert roman numerals into decimal nummbers in ppython python roman numerals to integer roman numerals as numbers python code given an integer convert it to a roman numeral python Integers to Roman Numerals ONLINE INt to roman roman number to integer python roman numeral conversion python decimal to roman roman numeral to integer python int to roman numeral best way to convert roman number to integers in python integer to roman calculator python convert roman numerals to numbers Integer to Roman Solution integer to roman numeral how to convert roman numerals to numbers in python python code to convert numerical number into roman numerals integer to roman online converter integer \ to roman roman to int python convert roman number to integer in python Integer to Roman Number python 3 roman to integer convert roman numeral to integer python in one line convert roman numeral to integer python roman numerals to numbers python python roman to integer convert roman number to integer python program to convert integer to roman numeral 2. write a python class to convert a roman numeral to an integer python script to convert number to roman numeral convert number into roman numerals python roman numerals to integers python code convert roman to integer in python Roman to Integer.py roman to integer python code convert integer to roman convert roman numerals to numbers python convert roman numerals to numbers numeric to roman java python roman numeral to integer roman numeral to number python Roman to Integer python solution integer to roman numeral python integer to romans roman to integer python convert number to roman number in java programing java program to convert guven numbers to roman numerals roman to integer python convert integer to roman java that converts a Roman numeral to an integer python numerical to roman python roman to number python convert roman to integer python Write a Python class to convert a roman numeral to an integer. roman to integer Write a class to represent Roman numerals python write a python program to convert a roman numeral to an integer integer to roman numer integer to roman numerals int to roman convert integer to roman numeral integer to roman
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source