No title

Anonymous Coward 2018-03-06 20:03:15.572818 UTC

1class binary:
2 def __init__(self, bStr: str):
3 if bin(bStr)[:2] != '0b':
4 raise ValueError('not a binary string!')
5
6 for bit in bStr[:2]:
7 if bit != '0' and bit != '1':
8 raise ValueError('not a binary string!')
9
10 self.b = bStr[:2]
11
12--------------------------------------------------------
13
14>>> binary(bin(5))
15Traceback (most recent call last):
16 File "<stdin>", line 1, in <module>
17 File "student.py", line 17, in __init__
18 if bin(bStr)[:2] != '0b':
19TypeError: 'str' object cannot be interpreted as an integer
20>>>