A module to represent numbers by their place value.
Project description
Version: 0.1
- This module provides a way to represent the place values in a given number, eg:
>>> 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
- This raises TypeError when you give it an invalid number, eg:
>>> a = NumRep('notanumber1111') Traceback (most recent call last): ... TypeError: Not a valid Number.
- And Every integer in the NumRep has a GetRep() method, which returns the Representation of the number itself, eg:
>>> 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)
- You can also do arithmetic operations on them and then use GetRep(), eg:
>>> a = NumRep(123456789) >>> a NumRep(Crores=12,Lakhs=34,Thousands=56,Hundreds=7,Tens=8,Ones=9) >>> (a.crores - 2).GetRep() NumRep(Tens=1)
- You can compare and do arithmetic operations NumReps with integers and also with other NumReps, like:
>>> 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)
- This class also provides an all() function, which gives you the real value of the given denomination, eg:
>>> a = NumRep(1234456789123) >>> a.all('hundreds') 12344567891
- You can also use the values specified in the module for all(), eg:
>>> a = NumRep(1234456789123) >>> a.all(CRORES) 123445
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
NumRep-0.1.tar.gz
(4.4 kB
view details)
File details
Details for the file NumRep-0.1.tar.gz
.
File metadata
- Download URL: NumRep-0.1.tar.gz
- Upload date:
- Size: 4.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7111e93b0b0879af1bad76fd18a053d1ccd459a28df28264c3106e83c2a82c69 |
|
MD5 | 50acb0edeb042f5a06eef70b0056a51d |
|
BLAKE2b-256 | 5575071690333063b9a19ebd9fdb19505666851115bdb0b157e1791dfd9e3c17 |