Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Reverse Roman Numerals by ppitek40
def liczba(slowo, i):
if slowo[i] == "I":
return 1
elif slowo[i] == "V":
return 5
elif slowo[i] == "X":
return 10
elif slowo[i] == "L":
return 50
elif slowo[i] == "C":
return 100
elif slowo[i] == "D":
return 500
elif slowo[i] == "M":
return 1000
def reverse_roman(roman_string):
wynik = 0
temp = 0
dlugosc = len(roman_string)
for char in range(1, dlugosc+1):
print(char)
licznik = char * -1
temp = liczba(roman_string, licznik)
print(temp)
if char != 1:
if temp < liczba(roman_string, (licznik + 1)):
wynik -= temp
else:
wynik += temp
else:
wynik += temp
#print(wynik)
return wynik
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
assert reverse_roman('MMMCMXCIX') == 3999, '6'
assert reverse_roman('LXXVI') == 76, '76'
assert reverse_roman('CDXCIX') == 499, '499'
assert reverse_roman('MMMDCCCLXXXVIII') == 3888, '3888'
print('Great! It is time to Check your code!');
Dec. 16, 2017