Read Binary by Hand

Binary notation stores numbers using only 0 and 1, just like computers do internally. Write parse_binary, which manually converts the string digits from binary to a decimal integer without using int(x, 2). If the string contains any character other than 0 or 1, raise ValueError.

Примеры

Ввод
"0"
Вывод
0
Ввод
"1"
Вывод
1
Ввод
"100"
Вывод
4

Нужно реализовать

def parse_binary(digits: str) -> int:

Теги

mathstrings
PostgreSQLv16

Hier verschijnt het resultaat van je code

Visible tests
1
Input
"0"
Expected0
2
Input
"1"
Expected1
3
Input
"100"
Expected4
4
Input
"1001"
Expected9
5
Input
"11010"
Expected26
6
Input
"10001101000"
Expected1128
Focus radio
Paused · SomaFM · Fluid