Created
June 25, 2015 16:08
-
-
Save wmantly/98c2c959da22bb9b3991 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
| class my_int( int ): | |
| def roman( self ): | |
| romanNum = [] | |
| symbols = ( ( 'M', 1000 ), ( 'C', 100 ), ( 'XC', 90 ), ( 'L', 50), ( 'X', 10 ), | |
| ( 'IX', 9 ), ('V', 5) , ( 'IV', 4 ), ( 'I', 1 ) ) | |
| for symbol, value in symbols: | |
| while self >= value: | |
| self -= value | |
| romanNum.append( symbol ) | |
| return ''.join(romanNum) | |
| n = my_int(56) | |
| print( n, n.roman() ) | |
| # alias not to change assert lines | |
| roman = my_int.roman | |
| assert roman( 11 ) == "XI", "11 should return XI" | |
| assert roman( 60 ) == "LX", "60 should return LX" | |
| assert roman( 78 ) == "LXXVIII", "78 should return LXXVIII" | |
| assert roman( 4 ) == "IV", "4 should return IV" | |
| assert roman( 99 ) == "XCIX", "99 should return XCIX" | |
| # Add your own assert tests below |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment