def decimal_converter(dec):
while dec > 1:
dec /= 10
return dec
def float_bin(num, p):
# split() separates whole number and decimal
# part and stores it in two separate variables
w, d = str(num).split(".")
# Convert both whole number and decimal
# part from string type to integer type
whole, dec = int(w), int(d)
# Convert the whole number part to it's
# respective binary form and remove the
# "0b" from it.
res = bin(whole).lstrip("0b") + "."
# Iterate the number of times, we want
# the number of decimal places to be
for i in range(p):
# Multiply the decimal value by 2
# and separate the whole number part
# and decimal part
whole, dec = str((decimal_converter(dec))*2).split(".")
# Convert the decimal part
# to integer again
dec = int(dec)
# Keep adding the integer parts
# receive to the result variable
res += whole
return res
#driver code
num = float(input("Enter your number = "))
p = int(input("Enter the number of decimal places of the result = "))
print(float_bin(num, p))