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
Влез, за да видиш историята на решенията
ВходВлез, за да използваш ИИ ментора
ВходVisible tests
1
Input
"0"Expected
02
Input
"1"Expected
13
Input
"100"Expected
44
Input
"1001"Expected
95
Input
"11010"Expected
266
Input
"10001101000"Expected
1128Focus radio
Paused · SomaFM · Fluid