Advertisement
IT45200

Untitled

May 10th, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.36 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. import re
  4. def convert_binary_to_int(b):
  5.      return int(b,2)
  6.    
  7. while True:
  8.     user_input= input("enter a binary form string : ")
  9.     if bool(re.match(r"\b[01]+\b",user_input)):
  10.         print("the conversion result is : " + str(convert_binary_to_int(user_input)))
  11.         break
  12.     else:
  13.         print("Only a binary string form '0' and '1' is accepted!")
  14.         continue
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement