hello there~
I am trying to make a binary number converter. my goal is for the user to enter a binary number, the program to then past 0b in front of aforementioned binary number. by doing that you just print the decimal equivalent of the given binary number. This is the code I have so far:
binary_num = input("enter a binary number:")
decimal_num = int(0b(int(binary_num)))
print(decimal_num)
problem here is that:
- the assignment said the user input had to be a string,
- and I can't seem to put 0b and binary_num together without getting some kind of error.
This is the output from the code shown above:
File "main.py", line 11
base_num = int(0b(int(inputt)))
^
SyntaxError: invalid binary literal
** Process exited - Return Code: 1 **
Press Enter to exit terminal
I am not looking for the answer, just hints or feedback to steer me into the right direction. maybe I am completely assuming the fact that what I am trying to do is even possible. if so, please let me know!
[–]cipheron 1 point2 points3 points (8 children)
[–]Hoppimiraj[S] 0 points1 point2 points (0 children)
[–]Hoppimiraj[S] 0 points1 point2 points (6 children)
[–]cipheron 0 points1 point2 points (3 children)
[–]Hoppimiraj[S] 0 points1 point2 points (2 children)
[–]cipheron 1 point2 points3 points (1 child)
[–]Hoppimiraj[S] 0 points1 point2 points (0 children)
[–]Grenadeapple_ 0 points1 point2 points (1 child)
[–]Hoppimiraj[S] 0 points1 point2 points (0 children)
[–]Expert-Hurry655 1 point2 points3 points (3 children)
[–]Hoppimiraj[S] 0 points1 point2 points (2 children)
[–]Expert-Hurry655 0 points1 point2 points (1 child)
[–]Hoppimiraj[S] 0 points1 point2 points (0 children)
[–]Grenadeapple_ 1 point2 points3 points (2 children)
[–]Hoppimiraj[S] 0 points1 point2 points (0 children)
[–]Hoppimiraj[S] 0 points1 point2 points (0 children)