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 - Unusual behaviour when drawing lots of images onto a large canvas -

how can i manage url using .htaccess in php? -

javascript - Chart.js - setting tooltip z-index -