- 2

Change the code to print binary equivalent of base ten numbers. Work in progress. I am also working on it

The code prints the binary equivalent of number input. https://code.sololearn.com/cqO4Mz7JJ6ci/?ref=app

22nd Aug 2021, 11:12 AM
Martin Raj Kumar
Martin Raj Kumar - avatar
5 Answers
+ 2
You set n to 0 then had a while loop that only executes while n is greater than 0. So that code will never run as written.
22nd Aug 2021, 11:32 AM
Slick
Slick - avatar
+ 1
Hi Martin! Here it is corrected code n = int(input()) b = "" while (n>0): r = n%2 b += str(r) n=n//2 print(b[::-1])
22nd Aug 2021, 12:02 PM
Python Learner
Python Learner - avatar
+ 1
Martin Raj Kumar Well, there's a much simpler way to do this: print(bin(num)[2:])
27th Aug 2021, 4:09 PM
Calvin Thomas
Calvin Thomas - avatar
0
Short n sweet ❀❀
22nd Aug 2021, 12:04 PM
Martin Raj Kumar
Martin Raj Kumar - avatar
- 2
Now you can find it. 😁
22nd Aug 2021, 11:14 AM
Martin Raj Kumar
Martin Raj Kumar - avatar