Finley Parr
@finleyparr
I am trying to make a binary converter for my GCSE in computer science and this is the code I am using;
num = int(input('Input number between 0 and 25
ash15khng I think this code would work:
print(f"Bin: {str(bin(int(input('Dec to bin: '))))[2:]}")
Explanation:
input() gets the number
int() turns it into an integer
bin() turns it into a binary integer
str() turns it into a string
[2:] removes the "0b" in front of it
The entire thing is in an "f string" which just makes it easier to format
And print() is to output the final string
Hope this helped!4 years ago
TheDrone7 Try to convert it into Binary first, then binary number to string and use the lstrip method on the string.4 years ago
pyelias Did your friends use some variant of bin(num).lstrip("- 0b")? The difference between that and what you did is that that lstrips the binary string, while you are lstriping the number itself, instead of a string.4 years ago