Update 03-roman-numerals/roman.py
This commit is contained in:
		| @ -1,19 +1,20 @@ | ||||
| def roman( self ): | ||||
| def roman( amount ): | ||||
| 	romanNum = [] | ||||
| 	symbols = ( ( 'M', 1000 ), ( 'C', 100 ), ( 'XC', 90 ), ( 'L', 50 ), ( 'X', 10 ), | ||||
| 		( 'IX', 9 ), ('V', 5 ) , ( 'IV', 4 ), ( 'I', 1 ) ) | ||||
| 	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 | ||||
| 		while amount >= value: | ||||
| 			amount -= value | ||||
| 			romanNum.append( symbol ) | ||||
|  | ||||
| 	return ''.join( romanNum ) | ||||
|  | ||||
| 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 | ||||
		Reference in New Issue
	
	Block a user