Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def isbin(num:str) ->bool:
- 'check string contains only binary digits and spaces'
- nums = num.split()
- if not nums: # treat empty as false
- return False
- for num in nums:
- if not set(num) <= {'0', '1'}:
- return False
- return True
- tests = ['', '0', '1', '101 111', '0x101 111 10001', '00001 000001 11111111']
- for test in tests:
- print(f'{test} gives {isbin(test)}')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement