From 11f0b2e0452e3857f3bdbb11ee334a628b645f92 Mon Sep 17 00:00:00 2001 From: William Mantly Date: Tue, 26 Sep 2023 00:26:50 +0000 Subject: [PATCH] Update 03-roman-numerals/roman.py --- 03-roman-numerals/roman.py | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/03-roman-numerals/roman.py b/03-roman-numerals/roman.py index 97341f2..d884199 100644 --- a/03-roman-numerals/roman.py +++ b/03-roman-numerals/roman.py @@ -1,22 +1,14 @@ -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 ) ) - 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 ) - 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 my_int.roman() not to change assert lines -roman = my_int.roman + return ''.join( romanNum ) assert roman( 11 ) == "XI", "11 should return XI" assert roman( 60 ) == "LX", "60 should return LX"