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

html - Cut text on left side inside button while centering -

plugins - CodeIgniter support on netbeans 8.0 -

php - Selecting items from MySQL for a status update feed efficiently while accounting for possible spam -