MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / oct_to_decimal

Function oct_to_decimal

conversions/octal_to_decimal.py:1–73  ·  view source on GitHub ↗

Convert a octal value to its decimal equivalent >>> oct_to_decimal("") Traceback (most recent call last): ... ValueError: Empty string was passed to the function >>> oct_to_decimal("-") Traceback (most recent call last): ... ValueError: Non-octal value w

(oct_string: str)

Source from the content-addressed store, hash-verified

1def oct_to_decimal(oct_string: str) -> int:
2 """
3 Convert a octal value to its decimal equivalent
4
5 >>> oct_to_decimal("")
6 Traceback (most recent call last):
7 ...
8 ValueError: Empty string was passed to the function
9 >>> oct_to_decimal("-")
10 Traceback (most recent call last):
11 ...
12 ValueError: Non-octal value was passed to the function
13 >>> oct_to_decimal("e")
14 Traceback (most recent call last):
15 ...
16 ValueError: Non-octal value was passed to the function
17 >>> oct_to_decimal("8")
18 Traceback (most recent call last):
19 ...
20 ValueError: Non-octal value was passed to the function
21 >>> oct_to_decimal("-e")
22 Traceback (most recent call last):
23 ...
24 ValueError: Non-octal value was passed to the function
25 >>> oct_to_decimal("-8")
26 Traceback (most recent call last):
27 ...
28 ValueError: Non-octal value was passed to the function
29 >>> oct_to_decimal("1")
30 1
31 >>> oct_to_decimal("-1")
32 -1
33 >>> oct_to_decimal("12")
34 10
35 >>> oct_to_decimal(" 12 ")
36 10
37 >>> oct_to_decimal("-45")
38 -37
39 >>> oct_to_decimal("-")
40 Traceback (most recent call last):
41 ...
42 ValueError: Non-octal value was passed to the function
43 >>> oct_to_decimal("0")
44 0
45 >>> oct_to_decimal("-4055")
46 -2093
47 >>> oct_to_decimal("2-0Fm")
48 Traceback (most recent call last):
49 ...
50 ValueError: Non-octal value was passed to the function
51 >>> oct_to_decimal("")
52 Traceback (most recent call last):
53 ...
54 ValueError: Empty string was passed to the function
55 >>> oct_to_decimal("19")
56 Traceback (most recent call last):
57 ...
58 ValueError: Non-octal value was passed to the function
59 """
60 oct_string = str(oct_string).strip()

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected