Created
April 14, 2016 12:57
-
-
Save hackerdem/208840ea1f85fc525ef8090a225bfd70 to your computer and use it in GitHub Desktop.
Write a Python program to convert a roman numeral to an integer.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class A: | |
def convert(self,roman): | |
num_list=[1,4,5,9,10,40,50,90,100,400,500,900,1000] | |
rom_list=['I','IV','V','IX','X','XL','L','XC','C','CD','D','CM','M'] | |
next_val= 0 | |
for i in range(len(roman)): | |
if i!=len(roman)-1: | |
if rom_list.index(roman[i])>=rom_list.index(roman[i+1]): | |
next_val+=num_list[rom_list.index(roman[i])] | |
else: | |
next_val-=num_list[rom_list.index(roman[i])] | |
else:next_val+=num_list[rom_list.index(roman[i])] | |
print(next_val) | |
listo=['MCMXCVI','XXXVI','MMMMCMXCIX','MMMMMMDCCLXXVII'] | |
for i in listo: | |
A().convert(i) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment