r/PythonLearning
•
u/Hour_Function673
•
Oct 02 '26
•
1
just finished my first Python coding challenge
Today I finished a small Python challenge on freeCodeCamp: converting decimal numbers to binary without using Python's built-in conversion function.
I had to figure out the logic myself using loops, conditions, lists, division and remainders.
It was a bit tricky at first, especially handling the last division and reversing the results, but I finally got it working.
I'm still a beginner, so I'd appreciate any feedback on my approach or suggestions for improving my code
158
Upvotes
1
u/jonrsharpe Oct 03 '26
Next the logic:
decimal = decimal // 2appears in two places, so can be moved outside the conditional, and simplified using the in-place operator todecimal //= 2.I also considered simplifying to
else, as ifdecimal % 2isn't0there's only one other option, but at this point it should be really clear that we can simplify further than that by just appending the remainder:to: