罗马数字转换程序的开发与测试
1. 阶段3:处理 toRoman 函数的错误输入
1.1 代码实现
#Define exceptions
class RomanError(Exception): pass
class OutOfRangeError(RomanError): pass
class NotIntegerError(RomanError): pass
class InvalidRomanNumeralError(RomanError): pass
#Define digit mapping
romanNumeralMap = (('M', 1000),
('CM', 900),
('D', 500),
('CD', 400),
('C', 100),
('XC', 90),
('L', 50),
('XL', 40),
('X', 10),
('IX', 9),
('V', 5),
('IV', 4),
('I', 1))
def toRoman(n):
"""convert integer to Roman numer
超级会员免费看
订阅专栏 解锁全文
121

被折叠的 条评论
为什么被折叠?



