Created
October 9, 2013 12:44
-
-
Save hiway/6900668 to your computer and use it in GitHub Desktop.
A quick n' dirty hack for doing math and getting output in Devanagari script (Unicode) instead of ASCII.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
def devanagari_math(statement): | |
trans = { | |
u'१':'1', | |
u'२':'2', | |
u'३':'3', | |
u'४':'4', | |
u'५':'5', | |
u'६':'6', | |
u'७':'7', | |
u'८':'8', | |
u'९':'9', | |
u'०':'0', | |
u'.':'.', | |
} | |
statement = statement.decode('utf-8') | |
for char in trans: | |
if char in statement: | |
statement = statement.replace(char, trans[char]) | |
output = str(eval(statement)) | |
for char in trans: | |
if trans[char] in output: | |
output = output.replace(trans[char], char) | |
return output | |
print devanagari_math('२.०/३.०') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice!