Created
May 19, 2015 02:05
-
-
Save ramalho/fd8c1517e9dc3b7f57f6 to your computer and use it in GitHub Desktop.
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
| """ | |
| romanos.py - arabicos para romanos | |
| >>> ara2rom(1) | |
| 'I' | |
| >>> ara2rom(2) | |
| 'II' | |
| >>> ara2rom(3) | |
| 'III' | |
| >>> ara2rom(4) | |
| 'IV' | |
| >>> ara2rom(5) | |
| 'V' | |
| >>> ara2rom(6) | |
| 'VI' | |
| >>> ara2rom(7) | |
| 'VII' | |
| >>> ara2rom(8) | |
| 'VIII' | |
| >>> ara2rom(9) | |
| 'IX' | |
| >>> ara2rom(10) | |
| 'X' | |
| >>> ara2rom(11) | |
| 'XI' | |
| >>> ara2rom(12) | |
| 'XII' | |
| >>> ara2rom(14) | |
| 'XIV' | |
| >>> ara2rom(15) | |
| 'XV' | |
| """ | |
| def unidade(a): | |
| pass | |
| def ara2rom(a): | |
| dic = { | |
| 4 : 'IV', | |
| 9 : 'IX', | |
| 14: 'XIV' | |
| } | |
| if a in dic: | |
| return dic[a] | |
| elif a <= 20: | |
| one = a % 5 | |
| five = a / 5 | |
| ten = a / 10 | |
| if a >= 10 : | |
| five = 0 | |
| if a == 15: | |
| five = 1 | |
| return 'X' * ten + 'V' * five + 'I' * one |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment