Q:

Python Binary Converter

I am new to python and trying to write a binary converter. I want to know if there is a way to check if a value entered is 0 or 1.
Example:
binary = userinput

check to see if the 8 bit numbers entered by the user are all binary numbers.

A:

Try this one:
bin_str = raw_input('Enter a binary number: ')

try:
    bin_num = int(bin_str, 2)
    print "Valid binary number entered. - " + bin_str
except ValueError:
    print "Invalid number entered."

Hope that's what you are looking for.

