Problem:


博士が愛した２進数

  「君の靴のサイズはいくつかね」 

  初対面の私に、いきなり博士は尋ねました。

  「 23.5 です」

  「ほお、実にきりのいい数字だ。2 の 4 乗に 2 の 2 乗と 2 の 1 乗と 2 の 0 乗と 2 の  -1  乗を 加えた数だ」

  続けて博士は尋ねました。

  「君、身長はいくつかね」

  「はい、158.1 です」

  博士は腕組みをして目を閉じました。しばらくの沈黙の後、口を開きました。

  「ナァ~」

  その後一緒に過ごした時間の中で、博士の行動がだんだん理解できるようになりました。

  まず、 私が博士の求めに応じて実数を言います。実数が整数部 8 桁以内で小数部 4 桁以内の 2 進数で表される場合、博士は 2 進数への変換結果を満足げに語ります。そうでない場合、悲しげに「ナァ~」 と鳴きます。これは、私が負の実数を言うまで繰り返されるのです。

  さて、博士は年齢とともにだんだんに長い計算が難しくなってきました。そこで、みなさんが博士に代わって、実数を入力し 2 進数に変換・出力するプログラムを作ってあげてください。ただし、2 進表現が制限桁数 (整数部 8 桁以内 + 小数部 4 桁以内) に収まらない場合は、NA (半角英字) を出力してください。入力される実数は整数部 8 桁以内、小数部 4 桁以内に収まるものとし、出力する 2 進表現は整数部 8 桁、小数部 4 桁で出力してください。

Input

複数のデータセットの並びが入力として与えられます。入力の終わりは負の実数ひとつの行で示されます。
各データセットとして１つの実数 n が１行に与えられます。

データセットの数は 1200 を超えません。

Output

入力データセットごとに 2 進数への変換結果を出力します。

Sample Input

23.5
158.1
-1.0

Output for the Sample Input

00010111.1000
NA



Sample input:
23.5
158.1
-1.0


Sample output:
00010111.1000
NA

Submission status: Wrong Answer

Solution code:
while(1):
    n=float(raw_input())
    if n<0:
        break
    else:
        nn=int(n*32)
        f=""
        for i in range(12):
            d=nn/2**(12-i)
            f=f+str(d)
            if i==7:
                f=f+"."
            nn=nn%2**(12-i)
        if nn==0:
            print f
        else:
            print "NA"

Submission status: Wrong Answer

Solution code:
while(1):
    n=float(raw_input())
    if n<0:
        break
    else:
        nn=int(n*32)
        f=""
        if nn>=2**(13):
            print "NA"
        else:
            for i in range(12):
                d=nn/2**(12-i)
                f=f+str(d)
                if i==7:
                    f=f+"."
                nn=nn%2**(12-i)
            if nn==0:
                print f
            else:
                print "NA"

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
def seisu(a):
    b = str(bin(int(a//1)))[2:]
    if len(b) > 9:
        print "NA"
        raise ValueError
    else:
        return b
        
def shosu(a):
    c = a - a//1
    f = []
    digit = 0
    while digit < 5:
        new_c = 2 * c
        seisu_part = int(new_c//1)
        shosu_part = new_c - seisu_part      
        f.append(seisu_part)
        if shosu_part == 0:
            return "".join(map(str, f)) 
        c = shosu_part
        digit += 1
    else:
        print "NA"
        raise ValueError

if __name__ == "__main__":
    while True:
        a = float(raw_input())
        if a < 0: 
            break
        try:
            sei = seisu(a) # ??´??°??¨???
            sho = shosu(a) # ?°???°?????\?????¨???
        except ValueError:
            break 
          
        print sei.zfill(8) + "." + str(sho).ljust(4,"0")

Submission status: Wrong Answer

Solution code:
while True:
    d= float(input())
    if d< 0: break
    a, b= bin(int(d))[2:].zfill(8)+".", d-int(d)
    for _ in range(4):
        b*= 2
        a= a+'1' if int(b)>= 1 else a+'0'
        if str(b).split(".")==['1','0']: break
        b-=int(b)
    a= a.ljust(13, '0')
    print("NA" if len(a)> 13 else a)

Submission status: Wrong Answer

Solution code:
# AOJ 0220 Binary Digit A Doctor Loved
# Python3 2018.6.23 bal4u

while 1:
	s = input()
	if s[0] == '-': break
	w = len(s)
	if s.find('.') < 0: a, b = int(s), 0
	elif w == 1: a, b = 0, 0
	elif s[0] == '.': a, b = 0, int(s[1:])
	else:
		if s[w-1] == '.': s += '0'
		a, b = map(int, s.split('.'))
	if a > 255:
		print("NA")
		continue
	sa = format(a, '08b')
	sb, s = '', str(b)
	k = 10**len(s)
	for i in range(4):
		b *= 2
		if b >= k: sb += '1'
		else: sb += '0'
		b %= k
	if b == 0: print(sa, '.', sb, sep='')
	else: print("NA")

Submission status: Wrong Answer

Solution code:
def to_digit(f):
  u = int(f)
  d = f - u
  us = ""
  if u == 0:
    us = "0"
  cnt = 8
  while u:
    if cnt == 0:
      return ("DAME", "DESU!!")
    cnt -= 1
    us += str(u % 2)
    u //= 2
  us += "0" * cnt
  us = us[::-1]

  ds = ""
  acc = 0.5
  cnt = 4
  while d:
    if cnt == 0:
      return ("DAME", "DESU!!")
    cnt -= 1
    if acc >= d:
      d -= acc
      ds += "1"
      acc /= 2
    else:
      ds += "0"
      acc /= 2
  ds += "0" * cnt
  return (us, ds)

while True:
  f = float(input())
  if f < 0:
    break
  us, ds = to_digit(f)
  if us == "DAME":
    print("NA")
  else:
    print(us.zfill(8) + "." + ds.zfill(4))

Submission status: Wrong Answer

Solution code:
def to_digit(f):
  u = int(f)
  d = f - u
  us = ""
  if u == 0:
    us = "0"
  cnt = 8
  while u:
    if cnt == 0:
      return ("DAME", "DESU!!")
    cnt -= 1
    us += str(u % 2)
    u //= 2
  us += "0" * cnt
  us = us[::-1]

  ds = ""
  cnt = 4
  while d > 0:
    if cnt == 0:
      return ("DAME", "DESU!!")
    cnt -= 1
    d *= 2
    if d >= 1:
      d -= 1
      ds += "1"
    else:
      ds += "0"
  ds += "0" * cnt
  return (us, ds)

while True:
  f = float(input())
  if f < 0:
    break
  us, ds = to_digit(f)
  if us == "DAME":
    print("NA")
  else:
    print(us.zfill(8) + "." + ds.zfill(4))

Submission status: Wrong Answer

Solution code:
def to_digit(f):
  u = int(f)
  d = f - u
  us = ""
  if u == 0:
    us = "0"
  cnt = 8
  while u:
    if cnt == 0:
      return ("DAME", "DESU!!")
    cnt -= 1
    us += str(u % 2)
    u //= 2
  us += "0" * cnt
  us = us[::-1]

  ds = ""
  cnt = 4
  acc = 1
  while d > 0:
    if cnt == 0:
      return ("DAME", "DESU!!")
    cnt -= 1
    acc /= 2
    if d >= acc:
      d -= acc
      ds += "1"
    else:
      ds += "0"
  ds += "0" * cnt
  return (us, ds)

while True:
  f = float(input())
  if f < 0:
    break
  us, ds = to_digit(f)
  if us == "DAME":
    print("NA")
  else:
    print(us, ds, sep=".")

Submission status: Wrong Answer

Solution code:
while True:
    #a,b=map(int,raw_input().split("."))                                                
    a=input()
    if a<0:break
    s,s2="",""

#    while a!=0:                                                                        
#       s+=str(a%2)                                                                     
#        a/=2                                                                           
    cnt=0



    if len(s2)<=4:
        print "%08d"%(int(format(int(a),"b")))
    else:
        print "NA"

"""                                                                                     
    while b!=0 and cnt<=4:                                                              
        b*=2                                                                            
        s2+=str(b/10)                                                                   
        b%=10                                                                           
        cnt+=1                                                                          
    s2="0"*4                                                                            
                                                                                        
"""

Submission status: Wrong Answer

Solution code:
while True:
    a=input()
    if a<0:break
    cnt=0
    b=a-int(a)
    s=""
    while b!=0.0 and cnt<=4:
        b*=2
        s+=str(int(b))
        b=b-1 if b>=1.0 else b
        cnt+=1
    s+="0"*(4-len(s))
    if len(s)<=4:
        print "%08d.%d"%(int(format(int(a),"b")),int(s))
    else:
        print "NA"

Submission status: Wrong Answer

Solution code:
while True:
    a=input()
    if a<0:break
    cnt=0
    b=a-int(a)
    s=""
    while b!=0.0 and cnt<=4:
        b*=2
        s+=str(int(b))
        b=b-1 if b>=1.0 else b
        cnt+=1
    s+="0"*(4-len(s))
    if cnt<=4:
        print "%08d.%d"%(int(format(int(a),"b")),int(s))
    else:
        print "NA"

Submission status: Wrong Answer

Solution code:
while True:
    a=input()
    if a<0:break
    cnt=0
    b=a-int(a)
    s=""
    while b!=0.0:
        b*=2
        s+=str(int(b))
        b=b-1 if b>=1.0 else b
        cnt+=1
	if cnt>=10:break
    else:
        s+="0"*(4-len(s))
    if cnt<=4:
        print "%08d.%d"%(int(format(int(a),"b")),int(s))
    else:
        print "NA"

Submission status: Wrong Answer

Solution code:
while True:
    a=input()
    if a<0:break
    cnt=0
    b=a-int(a)
    s=""
    while b!=0.0:
        b*=2
        s+=str(int(b))
	b=b-1.0 if b>=1.0 else b
        cnt+=1
        if cnt>=10:break
    else:
        s+="0"*(4-len(s))
    if cnt<=4 and len(s)<=4:
        print "%08d.%d"%(int(format(int(a),"b")),int(s))
    else:
        print "NA"

Submission status: Wrong Answer

Solution code:
while True:
    a=input()
    if a<0:break
    cnt=0
    b=a-int(a)
    b*=pow(2,10)
    s=format(int(b),"b")
    if "1" not in s[-6:]:
        print "%08d.%d"%(int(format(int(a),"b")),int(s[:4]))
    else:
        print "NA"

Submission status: Wrong Answer

Solution code:
while True:
    a=input()
    if a<0:break
    b=a-int(a)
    b*=pow(2,20)
    s=format(int(b),"b")
    if "1" not in s[-6:]:
        print "%08d.%4d"%(int(format(int(a),"b")),int(s[:4]))
    else:
        print "NA"

Submission status: Wrong Answer

Solution code:
while True:
    a=input()
    if a<0:break
    b=a-int(a)
    b*=pow(2,20)
    s=format(int(b),"b")
    if "1" not in s[-6:]:
        print "%08d.%04d"%(int(format(int(a),"b")),int(s[:4]))
    else:
        print "NA"

Submission status: Wrong Answer

Solution code:
while True:
    a=input()
    if a<0:break
    b=a-int(a)
    b*=pow(2,20)
    s=format(int(b),"b")
    c=format(int(a),"b")
    if ("1" not in s[4:]) and len(c)<=8:
        print "%08d.%04d"%(int(c),int(s[:4]))
    else:
        print "NA"

Submission status: Wrong Answer

Solution code:
dic={
0.0:0000,
0.5:1000,
0.25:0100,
0.125:0010,
0.0625:0001,
0.75:1100,
0.625:1010,
0.5625:1001,
0.375:0110,
0.3125:0101,
0.1875:0011,
0.875:1110,
0.8125:1101,
0.6875:1011,
0.4375:0111,
0.9375:1111}
while True:
    a=input()
    if a<0:break
    b=a-int(a)
    c=format(int(a),"b")
    if (b in dic) and len(c)<=8:
        print "%08d.%d"%(int(c),dic[b])
    else:
        print "NA"

Submission status: Time Limit Exceeded

Solution code:
while True:
    d= float(input())
    if d< 0: break
    a, b= bin(int(d))[2:].zfill(8)+".", d-int(d)
    while 1:
        b*= 2
        a= a+'1' if int(b)>= 1 else a+'0'
        if str(b).split(".")==['1','0']: break
        b-=int(b)
    a= a.ljust(13, '0')
    print("NA" if len(a)> 13 else a)

Submission status: Memory Limit Exceeded

Solution code:
while True:
    d= float(input())
    if d< 0: break
    a, b= int(d), d-int(d)
    x, y=[], []
    while a> 0:
        x.append(a%2)
        a= a//2
    if len(x)< 8:
        x.append((8-len(x))*"0")
    else:
        print("NA")
        continue
    while int(b)!=1:
        y.append(int(b*2))
        b= b*2
    if len(y)< 4:
        y.append((4-len(y))*"0")
        y.insert(0, '.')
        z= x[::-1]+y
        print(''.join(map(str, z)))
    else:
        print("NA")

Submission status: Accepted

Solution code:
while(True):
    n = float(input())
    if n < 0: break
    if int(n*16)-n*16: print("NA"); continue
    else:
        s = bin(int(n*16))[2:].zfill(12)
        print(s[:-4]+"."+s[-4:])

Submission status: Accepted

Solution code:
from decimal import Decimal

while 1:
    n = Decimal(input())
    if n < 0:break
    d1 = int(n)
    d2 = n - d1
    s1 = format(d1,'b').zfill(8)
    if len(s1) > 8:
        print('NA')
        continue
    r = str(s1) + '.'
    for i in range(4):
        spam = int(d2 * 2)
        r += str(spam)
        d2 = d2*2 - spam
    if d2 > 0:
        print('NA')
        continue
    print(r)

Submission status: Accepted

Solution code:
while(1):
    n=float(raw_input())
    if n<0:
        break
    else:
        nn=int(n*32)
        f=""
        if nn>=2**(13):
            print "NA"
        elif nn!=n*32:
            print "NA"
        else:
            for i in range(12):
                d=nn/2**(12-i)
                f=f+str(d)
                if i==7:
                    f=f+"."
                nn=nn%2**(12-i)
            if nn==0:
                print f
            else:
                print "NA"

Submission status: Accepted

Solution code:
import sys
f = sys.stdin

while True:
    n = float(f.readline())
    if n < 0:
        break
    output = bin(int(n))[2:].zfill(8) + '.'

    decimal = n - int(n)
    for i in range(4):
        decimal *= 2
        if 1 <= decimal:
            decimal -= 1
            output += '1'
        else:
            output += '0'
            
    if 1e-10 < decimal or 13 < len(output):
        print('NA')
    else:
        print(output)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
def seisu(a):
    b = str(bin(int(a//1)))[2:]
    if len(b) > 9:
        print "NA"
        raise ValueError
    else:
        return b
        
def shosu(a):
    c = a - a//1
    f = []
    digit = 0
    while digit < 5:
        new_c = 2 * c
        seisu_part = int(new_c//1)
        shosu_part = new_c - seisu_part      
        f.append(seisu_part)
        if shosu_part == 0:
            return "".join(map(str, f)) 
        c = shosu_part
        digit += 1
    else:
        print "NA"
        raise ValueError

if __name__ == "__main__":
    while True:
        try:
            a = float(raw_input())
        except:
            break
        if a < 0: 
            continue
        try:
            sei = seisu(a) # ??´??°??¨???
            sho = shosu(a) # ?°???°?????\?????¨???
        except ValueError:
            continue
        print sei.zfill(8) + "." + str(sho).ljust(4,"0")

Submission status: Accepted

Solution code:
while True:
    n = input()
    if n < 0:
        break
    m = int( n * 16)
    if m / 16.0 == n: #divided
         b = format(m, '012b')
         tmp = list(b)
         print "%s.%s" % ("".join(tmp[0:8]), "".join(tmp[8:12]))
    else:
        print "NA"

Submission status: Accepted

Solution code:
while 1:
    n = float(input())
    if n<0:break
    m=n-int(n)
    a=bin(int(n))[2:].zfill(8)+'.'
    for _ in range(4):
        m*=2
        if m>=1:
            a+='1'
            m-=1
        else: a+='0'
    print('NA' if m>1e-10 or 13<len(a) else a)

Submission status: Accepted

Solution code:
while True:
    d= float(input())
    if d< 0: break
    a= bin(int(d))[2:]
    if len(a)> 8:
        print("NA")
    else:
        a= a.zfill(8)+"."
        b= d-int(d)
        for _ in range(4):
            b*= 2
            if int(b)>= 1:
                a= a+'1'
                b-= 1
            else:
                a= a+'0'
        a= a.ljust(13, '0')
        print("NA" if 1e-10 < b or len(a)> 13 else a)

Submission status: Accepted

Solution code:
# Aizu Problem 0220: Binary Digit A Doctor Loved

import sys, math, os, struct

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")



while True:
    n = float(input())
    if n < 0:
        break
    pre = int(n)
    post = n - int(n)
    res = bin(pre)[2:].zfill(8) + '.'
    for k in range(4):
        post *= 2
        res += str(int(post))
        post -= int(post)
    if pre > 255 or post > 0:
        print("NA")
    else:
        print(res)
    #m = int(n * 16)
    #if n == m / 16. and m < 4096:
    #    res = ""
    #    for k in range(12):
    #        res += str(m % 2)
    #        m //= 2
    #        if k == 7:
    #            res += '.'
    #    print(res)
    #else:
    #    print("NA")

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0220

"""
import sys
from sys import stdin
input = stdin.readline


def solve(f):
    if f >= 256.0:
        return 'NA'
    f *= 16
    int_f = int(f)
    if f != int_f:
        return 'NA'
    bin_f = bin(int_f)[2:]
    fraction_p = bin_f[-4:]
    integer_p = bin_f[:-4]
    return integer_p.zfill(8) + '.' + fraction_p.zfill(4)


def main(args):
    while True:
        f = float(input())
        if f < 0.0:
            break
        result = solve(f)
        print(result)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

Solution code:
# AOJ 0220 Binary Digit A Doctor Loved
# Python3 2018.6.23 bal4u

while 1:
	s = input()
	if s[0] == '-': break
	if s.find('.') < 0: a, b = s, '0'
	else:
		a, b = s.split('.')
		if a == '': a = '0'
		if b == '': b = '0'
	k = 10**len(b)
	a, b = int(a), int(b)
	if a > 255:
		print("NA")
		continue
	sa = format(a, '08b')
	sb = ''
	for i in range(4):
		b *= 2
		if b >= k: sb += '1'
		else: sb += '0'
		b %= k
	if b == 0: print(sa, '.', sb, sep='')
	else: print("NA")

Submission status: Accepted

Solution code:
def to_digit(f):
  u = int(f)
  d = f - u
  us = ""
  if u == 0:
    us = "0" * 8
  else:
    cnt = 8
    while u:
      if cnt == 0:
        return ("DAME", "DESU!!")
      cnt -= 1
      us += str(u % 2)
      u //= 2
    us += "0" * cnt
    us = us[::-1]

  ds = ""
  cnt = 4
  acc = 1
  while d > 0:
    if cnt == 0:
      return ("DAME", "DESU!!")
    cnt -= 1
    acc /= 2
    if d >= acc:
      d -= acc
      ds += "1"
    else:
      ds += "0"
  ds += "0" * cnt
  return (us, ds)

while True:
  f = float(input())
  if f < 0:
    break
  us, ds = to_digit(f)
  if us == "DAME":
    print("NA")
  else:
    print(us, ds, sep=".")

Submission status: Accepted

Solution code:
while True:
    n = float(raw_input())
    if n<0.0 : break
    st = ""
    a = int(n)
    b = n - a
    for i in range(8):
        st = str(a%2) + st
        a /= 2
    st += "."
    for i in range(4):
        b *= 2
        st += str( int(b) )
        b -= int(b)
    if a>0 or b>0.00000000 :
        print "NA"
    else :
        print st

Submission status: Accepted

Solution code:
def convert(x,p):
    if p==12:
	return
    convert(x/2,p+1)
    if p==3:
        ans.append(".")
    ans.append(str(x%2))

while True:
    n=input()
    if n<0:break
    ans=[]
    shift=int(n*16)
    if n==shift/16.0 and shift<4096:
        convert(shift,0)
	print "".join(ans)
    else:
        print "NA"

Submission status: Accepted

Solution code:
while 1:
	a=16*float(raw_input())
	if a<0:break
	b=int(a)
	print "NA" if a!=b or a>4095 else "{:08b}.{:04b}".format(b/16,b%16)

Submission status: Accepted

Solution code:
def ans(N): # N:foat
    n=int(N)
    d=N-n
    ans_l=bin(n)[2:]
    ans_r=''
    for _ in range(4):
        ans_r+=str(int(d*2))
        d=d*2-int(d*2)
    if n>=256 or d!=0:
        return 'NA'
    else:
        return '0'*(8-len(ans_l))+ans_l+'.'+ans_r

while True:
    INP=float(input())
    if INP<0: break
    print(ans(INP))

Submission status: Accepted

Solution code:

d = dict()
for i in range(16):
    v = "{:04b}".format(i)
    k = i/16
    d[k] = v
    
while True:
    p = float(input())
    if p < 0:
        break
    
    i = int(p)
    f = p - i
    if f not in d:
        print("NA")
    else:
        print("{:08b}".format(i),end="")
        print(".",end="")
        print(d[f])

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

while True:
    N = input()
    if N.find(".") < 0:
        N = N + ".0"
    
    strA,strB = N.split(".")
    a = int(strA)
    if strA[0] == "-":
        break
    b = int(strB) * (10 ** (4-len(strB)))

    s1 = ""
    s2 = ""
    for i in range(8):
        if a > 0:
            s1 = str(a % 2) + s1
            a = a // 2
        else:
            s1 = "0" + s1
    
    for i in range(4):
        if b > 0:
            s2 = s2 + str((b * 2) // 10000) 
            b = (b * 2) % 10000
        else:
            s2 = s2 + "0"

    if a == 0 and b == 0:
        print(s1 + "." + s2)
    else:
        print("NA")

Submission status: Runtime Error

Solution code:
# AOJ 0220 Binary Digit A Doctor Loved
# Python3 2018.6.23 bal4u

while 1:
	a, b = map(int, input().split('.'))
	if a < 0: break
	if a > 255:
		print("NA")
		continue
	sa = format(a, '08b')
	sb, s = '', str(b)
	k = 10**len(s)
	for i in range(4):
		b *= 2
		if b >= k: sb += '1'
		else: sb += '0'
		b %= k
	if b == 0: print(sa, '.', sb, sep='')
	else: print("NA")

Submission status: Runtime Error

Solution code:
while True:
    a,b=map(int,raw_input().split("."))
    if a<0:break
    s,s2="",""
    while a>=2:
        s+=str(a%2)
        a/=2
    else:
        s+=str(a)
    s=(s+"0"*(8-len(s)))[::-1]

    cnt=0
    while b!=0 and cnt<=4:
        b*=2
        s2+=str(b/10)
        b%=10
        cnt+=1
    s2+="0"*(4-len(s2))
    print s+"."+s2 if len(s2)<=4 else "NA"

Submission status: Runtime Error

Solution code:
while True:
    a,b=map(int,raw_input().split("."))
    if a<0:break
    s,s2="",""
    while a!=0:
        s+=str(a%2)
        a/=2
    cnt=0
    while b!=0 and cnt<=4:
        b*=2
        s2+=str(b/10)
        b%=10
        cnt+=1
    s2+="0"*(4-len(s2))
    if len(s2)<=4:
        print "%08d.%d"%(int(s[::-1]),int(s2))
    else:
        print "NA"

Submission status: Runtime Error

Solution code:
while True:
    a,b=map(int,raw_input().split("."))
    if a<0:break
    s,s2="",""
    while a!=0:
        s+=str(a%2)
        a/=2
    cnt=0

    s2="0"*4
    if len(s2)<=4:
        print "%08d"%(int(s[::-1]))
    else:
        print "NA"

Submission status: Runtime Error

Solution code:
while True:
    a,b=map(int,raw_input().split("."))
    if a<0:break
    s,s2="",""

#    while a!=0:                                                                        
#       s+=str(a%2)                                                                     
#        a/=2                                                                           
    cnt=0

    while b!=0 and cnt<=4:
        b*=2
	s2+=str(b/10)
        b%=10
        cnt+=1
    s2="0"*4

    if len(s2)<=4:
        print "%08d"%(int(format(a,"b")))
    else:
        print "NA"

Submission status: Runtime Error

Solution code:
while True:
    #a,b=map(int,raw_input().split("."))                                                
    a=input()
    if a<0:break
    s,s2="",""

#    while a!=0:                                                                        
#       s+=str(a%2)                                                                     
#        a/=2                                                                           
    cnt=0

    while b!=0 and cnt<=4:
        b*=2
	s2+=str(b/10)
        b%=10
        cnt+=1
    s2="0"*4

    if len(s2)<=4:
        print "%08d"%(int(format(int(a),"b")))
    else:
        print "NA"