Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Binary-Conversion_lu.py
- # With some error-handling form apaarfus
- # Functions
- def __isBinary(string):
- if string:
- for i in string:
- if not i.isnumeric():
- print('Error, contains non-numeric characters.')
- return False
- elif (int(i) < 0) or (int(i) > 1):
- print('Error, contains invalid digits.')
- return False
- else:
- print('Error, nothing was entered.')
- return False
- return True
- def __binaryToDecimal(string):
- decimal = 0
- for i in string:
- print("Processing: \"" + i + "\"...")
- decimal = decimal*2 + int(digit)
- return decimal
- return -1
- # Run
- strInput = input('Enter a number: ')
- if __isBinary(strInput):
- decimal = __binaryToDecimal(strInput)
- print("Binary: " + strInput)
- print("Decimal: " + str(decimal))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement