Skip to content

Instantly share code, notes, and snippets.

@Dineshs91
Created September 15, 2015 13:37
Show Gist options
  • Save Dineshs91/2a7de4f73f7ade7a7406 to your computer and use it in GitHub Desktop.
Save Dineshs91/2a7de4f73f7ade7a7406 to your computer and use it in GitHub Desktop.
Convert given no into rupee representation
# Money in INR(Indian Rupees)
def convert(no):
rev_no = no[::-1]
ans = ''
for index, char in enumerate(rev_no):
ans = char + ans
if index >= 2 and index % 2 == 0 and len(no) > index + 1:
ans = ',' + ans
return ans
print 'Input in INR:', convert('49')
print 'Input in INR:', convert('149')
print 'Input in INR:', convert('1497')
print 'Input in INR:', convert('14945')
print 'Input in INR:', convert('149999')
print 'Input in INR:', convert('1499994')
print 'Input in INR:', convert('14999942')
@Dineshs91
Copy link
Author

Output

1497 => 1,497
14945 => 14,945
149999 => 1,49,999
1499994 => 14,99,994
14999942 => 1,49,99,942

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