![]() ![]() It happens to be what you wrote as the comment! Similarly, I'd call the inverse function encode_roman_numeral(num). (And by "Arabic", we mean 0123456789, not ٠١٢٣٤٥٦٧٨٩.)īased on these concerns, I'd call it decode_roman_numeral(roman). It's just an abstract integer, which is conventionally rendered for you as base-ten Arabic digits when str() is called on it (whether explicitly or implicitly). It's not Arabic, nor is it even in base ten. Strictly speaking, the result is an int.Why is the parameter named t - what does it stand for?."get" implies retrieving something that already exists.Get_arabic_numbers(t) is not really named appropriately: The variable names were generally not helpful: l, i, t, c, li were all cryptic. The comments were generally helpful, but the code itself could have been easier to understand if it were shorter and more expressive. # If the number is at least 1 but smaller than 10 # If the number is at least 10 but smaller than 100 # If the number is at least 100 but smaller than 1000įormat = format + encode(l, c, 'I', 'V', "IX") # They are in the wrong order, so the list has to be reversedįormat = format + encode(l, c, 'C', 'D', "CM")įormat = format + encode(l, c, 'X', 'L', "XC") # int is not iterable, so I wrote this to get the digits # Special case 9.3: 900 depends on 1000, so it's 'CM' # Special case 9.2: 90 depends on 1000, so it's 'XC' # Special case 9.1: 9 depends on 10, so it's 'IX' # Convert from roman numeral to arabic number I got an idea to make a Roman/Arabic number converter, and I would like to hear your thoughts, where I could improve it, if there are Python specific things that I missed, so on and so forth.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |