Represent any number in Indian Format

This program can convert any given number into the format of Indian Number system. This program is done using python. Basically first the input is passed to a function fix() in which it reverse the number, then if the number's length is less then 3 then it is directly printed or else for first 3 digits of the reversed string a comma is printed and at every even position the comma is printed !

Screenshots



The Code

def fix(x):
 z=''
 i=0
 x=x[::-1]
 if(len(x)<=3):
  print x[::-1]
 else:
  while(i<len(x)):
    z=z+x[i]
    if(i==2):
     z=z+','
    elif(i>2 and i<len(x)-1):
     if((i)%2==0):
      z=z+','
    i=i+1
  print z[::-1]
  
for i in range(0, input()):
 #print '12'
 x=raw_input()
 fix(x)

Found Suggestions ?
Ping them here !

Comments

Popular posts from this blog

Non Restoring Division Algorithm Implementation in C

Hackerrank Modified Kaprekar Numbers Solution

Bit Stuffing Code Implementation in Java