Read Trinary Numbers
The trinary number system is like decimal, but it uses only the digits 0, 1, and 2. The function trinary receives a string string written in trinary form and converts it to a regular decimal number. If the string contains any invalid character, return 0.
Примеры
Ввод
"1"Вывод
1Ввод
"10"Вывод
3Ввод
"102101"Вывод
307Нужно реализовать
def trinary(string: str) -> int:
Теги
mathstrings
Idħol biex tara l-istorja tas-sottomissjonijiet
IdħolIdħol biex tuża l-Mentor tal-AI
IdħolVisible tests
1
Input
"1"Expected
12
Input
"10"Expected
33
Input
"102101"Expected
3074
Input
"2002"Expected
565
Input
"1a"Expected
06
Input
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"Expected
0Focus radio
Paused · SomaFM · Fluid