Finley Parr

@finleyparr (0)
finleyparr
finleyparr
shared a Post
3 years ago
1
Binary converter wont work
Ask
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
Read full post
ash15khng
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!3 years ago
TheDrone7
TheDrone7 Try to convert it into Binary first, then binary number to string and use the lstrip method on the string.3 years ago
pyelias
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.3 years ago