int1.py 1.29 KB
Newer Older
xyb's avatar
xyb committed
1
2
3
4
5
6
7
8
9
10
11
print(int(0))
print(int(1))
print(int(+1))
print(int(-1))

print(int('0'))
print(int('+0'))
print(int('-0'))
print(int('1'))
print(int('+1'))
print(int('-1'))
xyb's avatar
xyb committed
12
print(int('01'))
xyb's avatar
xyb committed
13
14
15
16
print(int('9'))
print(int('10'))
print(int('+10'))
print(int('-10'))
xyb's avatar
xyb committed
17
18
print(int('12'))
print(int('-12'))
xyb's avatar
xyb committed
19
20
21
22
23
24
25
26
27
print(int('99'))
print(int('100'))
print(int('314'))
print(int(' 314'))
print(int('314 '))
print(int('  \t\t  314  \t\t  '))
print(int('  1  '))
print(int(' -3 '))

xyb's avatar
xyb committed
28
29
30
31
32
33
34
35
print(int('0', 10))
print(int('1', 10))
print(int(' \t 1 \t ', 10))
print(int('11', 10))
print(int('11', 16))
print(int('11', 8))
print(int('11', 2))
print(int('11', 36))
xyb's avatar
xyb committed
36
print(int('0o123', 0))
xyb's avatar
xyb committed
37
print(int('8388607'))
xyb's avatar
xyb committed
38
39
print(int('0x123', 16))
print(int('0X123', 16))
40
print(int('0A', 16))
xyb's avatar
xyb committed
41
print(int('0o123', 8))
xyb's avatar
xyb committed
42
print(int('0O123', 8))
xyb's avatar
xyb committed
43
44
print(int('0123', 8))
print(int('0b100', 2))
xyb's avatar
xyb committed
45
print(int('0B100', 2))
xyb's avatar
xyb committed
46
47
48
print(int('0100', 2))
print(int(' \t 0o12', 8))
print(int('0o12  \t  ', 8))
xyb's avatar
xyb committed
49
50
51
52
53
54
55
56
57


def test(value, base):
    try:
        print(int(value, base))
    except ValueError:
        print('ValueError')


xyb's avatar
xyb committed
58
59
test('x', 0)
test('1x', 0)
xyb's avatar
xyb committed
60
test('  1x', 0)
xyb's avatar
xyb committed
61
test('  1' + chr(2) + '  ', 0)
xyb's avatar
xyb committed
62
63
64
65
66
67
68
69
70
71
72
73
74
test('', 0)
test(' ', 0)
test('  \t\t  ', 0)
test("\u0200", 0)
test('0x', 16)
test('0x', 0)
test('0o', 8)
test('0o', 0)
test('0b', 2)
test('0b', 0)
test('0b2', 2)
test('0o8', 8)
test('0xg', 16)
xyb's avatar
xyb committed
75
test('1 1', 16)