How do I limit an input in python so it will only allow 0 or 1's? -


ive got binary converter in python , want know how limit input numbers only, in case. 1's or 0's. 101010001 valid 44 not example. thanks.

you can try attempt convert integer binary, , print message if fails.

query = raw_input("enter binary number ")  try:     is_bin = int(query,2)     is_bin = true     print "correct number" except valueerror:     is_bin = false     print "not binary number" 

Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -