Basic Language Features
Fundamentals
Control Flow
// Change from original fork by adding compatability for Value protection, if the input is not a number, we will cancel rather than crash.
def convert_decimal_roman(number): try: number = int(number) except ValueError: print("Invalid Input, Value Error") return("Invalid Input") str = '' numDct = {1000: "M", 900: "CM", 500: "D", 400: "CD", 100: "C", 90: "XC", 50: "L", 40: "XL", 10: "X", 9: "IX", 5: "V", 4: "IV", 1: "I"} for key, value in numDct.items(): str += value * (number // key) number %= key return str
- def convert_decimal_roman(number):
number = int(number)- try:
- number = int(number)
- except ValueError:
- print("Invalid Input, Value Error")
- return("Invalid Input")
- str = ''
- numDct = {1000: "M",
- 900: "CM",
- 500: "D",
- 400: "CD",
- 100: "C",
- 90: "XC",
- 50: "L",
- 40: "XL",
- 10: "X",
- 9: "IX",
- 5: "V",
- 4: "IV",
- 1: "I"}
- for key, value in numDct.items():
- str += value * (number // key)
- number %= key
- return str
import codewars_test as test # TODO Write tests import solution # or from solution import example # test.assert_equals(actual, expected, [optional] message) @test.describe("Example") def test_group(): @test.it("test case") def test_case(): test.assert_equals(convert_decimal_roman('hello'), 'Invalid Input') test.assert_equals(convert_decimal_roman('bonjour'), 'Invalid Input') test.assert_equals(convert_decimal_roman('1234abcd'), 'Invalid Input') test.assert_equals(convert_decimal_roman('ifonlythiswaseasy'), 'Invalid Input') test.assert_equals(convert_decimal_roman('69'), 'LXIX') test.assert_equals(convert_decimal_roman('874'), 'DCCCLXXIV') test.assert_equals(convert_decimal_roman('938'), 'CMXXXVIII') test.assert_equals(convert_decimal_roman('442'), 'CDXLII') test.assert_equals(convert_decimal_roman('323'), 'CCCXXIII') test.assert_equals(convert_decimal_roman('548'), 'DXLVIII') test.assert_equals(convert_decimal_roman('386'), 'CCCLXXXVI') test.assert_equals(convert_decimal_roman('962'), 'CMLXII') test.assert_equals(convert_decimal_roman('217'), 'CCXVII') test.assert_equals(convert_decimal_roman('771'), 'DCCLXXI') test.assert_equals(convert_decimal_roman('997'), 'CMXCVII') test.assert_equals(convert_decimal_roman('175'), 'CLXXV') test.assert_equals(convert_decimal_roman('873'), 'DCCCLXXIII') test.assert_equals(convert_decimal_roman('33'), 'XXXIII') test.assert_equals(convert_decimal_roman('508'), 'DVIII') test.assert_equals(convert_decimal_roman('743'), 'DCCXLIII') test.assert_equals(convert_decimal_roman('326'), 'CCCXXVI') test.assert_equals(convert_decimal_roman('858'), 'DCCCLVIII') test.assert_equals(convert_decimal_roman('707'), 'DCCVII') test.assert_equals(convert_decimal_roman('459'), 'CDLIX') test.assert_equals(convert_decimal_roman('976'), 'CMLXXVI') test.assert_equals(convert_decimal_roman('855'), 'DCCCLV') test.assert_equals(convert_decimal_roman('840'), 'DCCCXL') test.assert_equals(convert_decimal_roman('682'), 'DCLXXXII') test.assert_equals(convert_decimal_roman('506'), 'DVI') test.assert_equals(convert_decimal_roman('553'), 'DLIII') test.assert_equals(convert_decimal_roman('1'), 'I') test.assert_equals(convert_decimal_roman('48'), 'XLVIII') test.assert_equals(convert_decimal_roman('125'), 'CXXV') test.assert_equals(convert_decimal_roman('353'), 'CCCLIII') test.assert_equals(convert_decimal_roman('137'), 'CXXXVII') test.assert_equals(convert_decimal_roman('423'), 'CDXXIII') test.assert_equals(convert_decimal_roman('26'), 'XXVI') test.assert_equals(convert_decimal_roman('362'), 'CCCLXII') test.assert_equals(convert_decimal_roman('587'), 'DLXXXVII') test.assert_equals(convert_decimal_roman('599'), 'DXCIX') test.assert_equals(convert_decimal_roman('589'), 'DLXXXIX') test.assert_equals(convert_decimal_roman('619'), 'DCXIX') test.assert_equals(convert_decimal_roman('261'), 'CCLXI') test.assert_equals(convert_decimal_roman('480'), 'CDLXXX') test.assert_equals(convert_decimal_roman('410'), 'CDX') test.assert_equals(convert_decimal_roman('776'), 'DCCLXXVI') test.assert_equals(convert_decimal_roman('625'), 'DCXXV') test.assert_equals(convert_decimal_roman('116'), 'CXVI') test.assert_equals(convert_decimal_roman('112'), 'CXII') test.assert_equals(convert_decimal_roman('603'), 'DCIII') test.assert_equals(convert_decimal_roman('549'), 'DXLIX') test.assert_equals(convert_decimal_roman('838'), 'DCCCXXXVIII') test.assert_equals(convert_decimal_roman('846'), 'DCCCXLVI') test.assert_equals(convert_decimal_roman('756'), 'DCCLVI') test.assert_equals(convert_decimal_roman('325'), 'CCCXXV') test.assert_equals(convert_decimal_roman('104'), 'CIV') test.assert_equals(convert_decimal_roman('669'), 'DCLXIX') test.assert_equals(convert_decimal_roman('822'), 'DCCCXXII') test.assert_equals(convert_decimal_roman('51'), 'LI') test.assert_equals(convert_decimal_roman('372'), 'CCCLXXII') test.assert_equals(convert_decimal_roman('824'), 'DCCCXXIV') test.assert_equals(convert_decimal_roman('136'), 'CXXXVI') test.assert_equals(convert_decimal_roman('89'), 'LXXXIX') test.assert_equals(convert_decimal_roman('693'), 'DCXCIII') test.assert_equals(convert_decimal_roman('81'), 'LXXXI') test.assert_equals(convert_decimal_roman('681'), 'DCLXXXI') test.assert_equals(convert_decimal_roman('306'), 'CCCVI') test.assert_equals(convert_decimal_roman('398'), 'CCCXCVIII') test.assert_equals(convert_decimal_roman('554'), 'DLIV') test.assert_equals(convert_decimal_roman('651'), 'DCLI') test.assert_equals(convert_decimal_roman('403'), 'CDIII') test.assert_equals(convert_decimal_roman('485'), 'CDLXXXV') test.assert_equals(convert_decimal_roman('815'), 'DCCCXV') test.assert_equals(convert_decimal_roman('88'), 'LXXXVIII') test.assert_equals(convert_decimal_roman('53'), 'LIII') test.assert_equals(convert_decimal_roman('610'), 'DCX') test.assert_equals(convert_decimal_roman('410'), 'CDX') test.assert_equals(convert_decimal_roman('376'), 'CCCLXXVI') test.assert_equals(convert_decimal_roman('791'), 'DCCXCI') test.assert_equals(convert_decimal_roman('594'), 'DXCIV') test.assert_equals(convert_decimal_roman('165'), 'CLXV') test.assert_equals(convert_decimal_roman('812'), 'DCCCXII') test.assert_equals(convert_decimal_roman('224'), 'CCXXIV') test.assert_equals(convert_decimal_roman('185'), 'CLXXXV') test.assert_equals(convert_decimal_roman('833'), 'DCCCXXXIII') test.assert_equals(convert_decimal_roman('994'), 'CMXCIV') test.assert_equals(convert_decimal_roman('385'), 'CCCLXXXV') test.assert_equals(convert_decimal_roman('821'), 'DCCCXXI') test.assert_equals(convert_decimal_roman('572'), 'DLXXII') test.assert_equals(convert_decimal_roman('428'), 'CDXXVIII') test.assert_equals(convert_decimal_roman('918'), 'CMXVIII') test.assert_equals(convert_decimal_roman('86'), 'LXXXVI') test.assert_equals(convert_decimal_roman('238'), 'CCXXXVIII') test.assert_equals(convert_decimal_roman('206'), 'CCVI') test.assert_equals(convert_decimal_roman('56'), 'LVI') test.assert_equals(convert_decimal_roman('72'), 'LXXII') test.assert_equals(convert_decimal_roman('380'), 'CCCLXXX') test.assert_equals(convert_decimal_roman('26'), 'XXVI') test.assert_equals(convert_decimal_roman('715'), 'DCCXV') test.assert_equals(convert_decimal_roman('168'), 'CLXVIII')
- import codewars_test as test
- # TODO Write tests
- import solution # or from solution import example
- # test.assert_equals(actual, expected, [optional] message)
- @test.describe("Example")
- def test_group():
- @test.it("test case")
- def test_case():
- test.assert_equals(convert_decimal_roman('hello'), 'Invalid Input')
- test.assert_equals(convert_decimal_roman('bonjour'), 'Invalid Input')
- test.assert_equals(convert_decimal_roman('1234abcd'), 'Invalid Input')
- test.assert_equals(convert_decimal_roman('ifonlythiswaseasy'), 'Invalid Input')
- test.assert_equals(convert_decimal_roman('69'), 'LXIX')
- test.assert_equals(convert_decimal_roman('874'), 'DCCCLXXIV')
- test.assert_equals(convert_decimal_roman('938'), 'CMXXXVIII')
- test.assert_equals(convert_decimal_roman('442'), 'CDXLII')
- test.assert_equals(convert_decimal_roman('323'), 'CCCXXIII')
- test.assert_equals(convert_decimal_roman('548'), 'DXLVIII')
- test.assert_equals(convert_decimal_roman('386'), 'CCCLXXXVI')
- test.assert_equals(convert_decimal_roman('962'), 'CMLXII')
- test.assert_equals(convert_decimal_roman('217'), 'CCXVII')
- test.assert_equals(convert_decimal_roman('771'), 'DCCLXXI')
- test.assert_equals(convert_decimal_roman('997'), 'CMXCVII')
- test.assert_equals(convert_decimal_roman('175'), 'CLXXV')
- test.assert_equals(convert_decimal_roman('873'), 'DCCCLXXIII')
- test.assert_equals(convert_decimal_roman('33'), 'XXXIII')
- test.assert_equals(convert_decimal_roman('508'), 'DVIII')
- test.assert_equals(convert_decimal_roman('743'), 'DCCXLIII')
- test.assert_equals(convert_decimal_roman('326'), 'CCCXXVI')
- test.assert_equals(convert_decimal_roman('858'), 'DCCCLVIII')
- test.assert_equals(convert_decimal_roman('707'), 'DCCVII')
- test.assert_equals(convert_decimal_roman('459'), 'CDLIX')
- test.assert_equals(convert_decimal_roman('976'), 'CMLXXVI')
- test.assert_equals(convert_decimal_roman('855'), 'DCCCLV')
- test.assert_equals(convert_decimal_roman('840'), 'DCCCXL')
- test.assert_equals(convert_decimal_roman('682'), 'DCLXXXII')
- test.assert_equals(convert_decimal_roman('506'), 'DVI')
- test.assert_equals(convert_decimal_roman('553'), 'DLIII')
- test.assert_equals(convert_decimal_roman('1'), 'I')
- test.assert_equals(convert_decimal_roman('48'), 'XLVIII')
- test.assert_equals(convert_decimal_roman('125'), 'CXXV')
- test.assert_equals(convert_decimal_roman('353'), 'CCCLIII')
- test.assert_equals(convert_decimal_roman('137'), 'CXXXVII')
- test.assert_equals(convert_decimal_roman('423'), 'CDXXIII')
- test.assert_equals(convert_decimal_roman('26'), 'XXVI')
- test.assert_equals(convert_decimal_roman('362'), 'CCCLXII')
- test.assert_equals(convert_decimal_roman('587'), 'DLXXXVII')
- test.assert_equals(convert_decimal_roman('599'), 'DXCIX')
- test.assert_equals(convert_decimal_roman('589'), 'DLXXXIX')
- test.assert_equals(convert_decimal_roman('619'), 'DCXIX')
- test.assert_equals(convert_decimal_roman('261'), 'CCLXI')
- test.assert_equals(convert_decimal_roman('480'), 'CDLXXX')
- test.assert_equals(convert_decimal_roman('410'), 'CDX')
- test.assert_equals(convert_decimal_roman('776'), 'DCCLXXVI')
- test.assert_equals(convert_decimal_roman('625'), 'DCXXV')
- test.assert_equals(convert_decimal_roman('116'), 'CXVI')
- test.assert_equals(convert_decimal_roman('112'), 'CXII')
- test.assert_equals(convert_decimal_roman('603'), 'DCIII')
- test.assert_equals(convert_decimal_roman('549'), 'DXLIX')
- test.assert_equals(convert_decimal_roman('838'), 'DCCCXXXVIII')
- test.assert_equals(convert_decimal_roman('846'), 'DCCCXLVI')
- test.assert_equals(convert_decimal_roman('756'), 'DCCLVI')
test.assert_equals(convert_decimal_roman('333'), 'CCCXXXIII')- test.assert_equals(convert_decimal_roman('325'), 'CCCXXV')
test.assert_equals(convert_decimal_roman('154'), 'CLIV')- test.assert_equals(convert_decimal_roman('104'), 'CIV')
- test.assert_equals(convert_decimal_roman('669'), 'DCLXIX')
- test.assert_equals(convert_decimal_roman('822'), 'DCCCXXII')
- test.assert_equals(convert_decimal_roman('51'), 'LI')
- test.assert_equals(convert_decimal_roman('372'), 'CCCLXXII')
- test.assert_equals(convert_decimal_roman('824'), 'DCCCXXIV')
- test.assert_equals(convert_decimal_roman('136'), 'CXXXVI')
- test.assert_equals(convert_decimal_roman('89'), 'LXXXIX')
- test.assert_equals(convert_decimal_roman('693'), 'DCXCIII')
- test.assert_equals(convert_decimal_roman('81'), 'LXXXI')
- test.assert_equals(convert_decimal_roman('681'), 'DCLXXXI')
- test.assert_equals(convert_decimal_roman('306'), 'CCCVI')
- test.assert_equals(convert_decimal_roman('398'), 'CCCXCVIII')
- test.assert_equals(convert_decimal_roman('554'), 'DLIV')
- test.assert_equals(convert_decimal_roman('651'), 'DCLI')
- test.assert_equals(convert_decimal_roman('403'), 'CDIII')
- test.assert_equals(convert_decimal_roman('485'), 'CDLXXXV')
- test.assert_equals(convert_decimal_roman('815'), 'DCCCXV')
- test.assert_equals(convert_decimal_roman('88'), 'LXXXVIII')
- test.assert_equals(convert_decimal_roman('53'), 'LIII')
- test.assert_equals(convert_decimal_roman('610'), 'DCX')
- test.assert_equals(convert_decimal_roman('410'), 'CDX')
- test.assert_equals(convert_decimal_roman('376'), 'CCCLXXVI')
- test.assert_equals(convert_decimal_roman('791'), 'DCCXCI')
- test.assert_equals(convert_decimal_roman('594'), 'DXCIV')
test.assert_equals(convert_decimal_roman('486'), 'CDLXXXVI')- test.assert_equals(convert_decimal_roman('165'), 'CLXV')
- test.assert_equals(convert_decimal_roman('812'), 'DCCCXII')
- test.assert_equals(convert_decimal_roman('224'), 'CCXXIV')
- test.assert_equals(convert_decimal_roman('185'), 'CLXXXV')
- test.assert_equals(convert_decimal_roman('833'), 'DCCCXXXIII')
- test.assert_equals(convert_decimal_roman('994'), 'CMXCIV')
- test.assert_equals(convert_decimal_roman('385'), 'CCCLXXXV')
- test.assert_equals(convert_decimal_roman('821'), 'DCCCXXI')
- test.assert_equals(convert_decimal_roman('572'), 'DLXXII')
- test.assert_equals(convert_decimal_roman('428'), 'CDXXVIII')
- test.assert_equals(convert_decimal_roman('918'), 'CMXVIII')
- test.assert_equals(convert_decimal_roman('86'), 'LXXXVI')
- test.assert_equals(convert_decimal_roman('238'), 'CCXXXVIII')
- test.assert_equals(convert_decimal_roman('206'), 'CCVI')
- test.assert_equals(convert_decimal_roman('56'), 'LVI')
test.assert_equals(convert_decimal_roman('279'), 'CCLXXIX')- test.assert_equals(convert_decimal_roman('72'), 'LXXII')
- test.assert_equals(convert_decimal_roman('380'), 'CCCLXXX')
- test.assert_equals(convert_decimal_roman('26'), 'XXVI')
- test.assert_equals(convert_decimal_roman('715'), 'DCCXV')
- test.assert_equals(convert_decimal_roman('168'), 'CLXVIII')