Skip to content

Instantly share code, notes, and snippets.

@hiway
Created October 9, 2013 12:44
Show Gist options
  • Save hiway/6900668 to your computer and use it in GitHub Desktop.
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.
#!/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('२.०/३.०')
@deepankarb
Copy link

Nice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment