From deef308dc451ba62faf8f30c39523de923f7a372 Mon Sep 17 00:00:00 2001 From: srishtiratna <56593893+srishtiratna@users.noreply.github.com> Date: Tue, 29 Oct 2019 21:42:24 +0530 Subject: [PATCH] code to convert decimal to binary numbers --- binary equivalent.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 binary equivalent.py diff --git a/binary equivalent.py b/binary equivalent.py new file mode 100644 index 0000000..0a2e220 --- /dev/null +++ b/binary equivalent.py @@ -0,0 +1,16 @@ +a=int(input("Enter a natural number"))#Taking input +if a==0: + print(0) +else: + l=[] + while(a>0): + b=a%2 #Calculating the remainder + a=a//2 #Updating the value of a + l.append(b) #Storing the values of b in a list + l.reverse() +print("The binary equivalent is:",end="") +for i in l: + print(i,end="") + + +