用数字的位值表示数字的模块。
NumRep的Python项目详细描述
numrep
版本:0.1.3
- 此模块提供了一种表示给定数字中的位值的方法,例如:
>>> a = NumRep(1234456789123) >>> a NumRep(Crores=123445,Lakhs=67,Thousands=89,Hundreds=1,Tens=2,Ones=3) >>> a.crores 123445 >>> a.ones 3 >>> a.hundreds 1 >>> a.tens 2 >>> a.lakhs 67 >>> print(a) 123445 Crores, 67 Lakhs, 89 Thousands, 1 Hundred, 2 Tens, 3 Ones
- 如果给它一个无效的数字,则会引发typeerror,例如:
>>> a = NumRep('notanumber1111') Traceback (most recent call last): ... TypeError: Not a valid Number.
- 并且numrep中的每个整数都有一个getrep()方法,该方法返回数字本身的表示形式,例如:
>>> a = NumRep(123456789) >>> a NumRep(Crores=12,Lakhs=34,Thousands=56,Hundreds=7,Tens=8,Ones=9) >>> a.crores 12 >>> a.crores.GetRep() NumRep(Tens=1,Ones=2) >>> a.crores.GetRep().tens.GetRep() NumRep(Ones=1)
- 您还可以对它们执行算术运算,然后使用getrep(),例如:
>>> a = NumRep(123456789) >>> a NumRep(Crores=12,Lakhs=34,Thousands=56,Hundreds=7,Tens=8,Ones=9) >>> (a.crores - 2).GetRep() NumRep(Tens=1)
- 您可以将numreps与整数以及其他numreps进行比较和算术运算,例如:
>>> c = NumRep(15) >>> c NumRep(Tens=1,Ones=5) >>> c + 10 NumRep(Tens=2,Ones=5) >>> b = NumRep(10) >>> b NumRep(Tens=1) >>> c + b NumRep(Tens=2,Ones=5)
- 这个类还提供了一个all()函数,它为您提供给定面额的实际值,例如:
>>> a = NumRep(1234456789123) >>> a.all('hundreds') 12344567891
- 您还可以使用模块中为all()指定的值,例如:
>>> a = NumRep(1234456789123) >>> a.all(CRORES) 123445
更改日志
- 0.1.3
- 另一个错误修复程序
- 0.1.2
- 修正了一个大错误。
- 0.1.1
- 定义str函数
- 添加主模块
- 0.1
- 现在可以对numrep对象进行比较和算术运算
- 使numrep成为一个包
- 0.0.1.1
- 为模块中的所有()函数添加variabes
- 0.0.1
- 首次发布