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
PostgreSQLv16

Itt jelenik meg a kód futtatásának eredménye

Visible tests
1
Input
"1"
Expected1
2
Input
"10"
Expected3
3
Input
"102101"
Expected307
4
Input
"2002"
Expected56
5
Input
"1a"
Expected0
6
Input
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
Expected0
Focus radio
Paused · SomaFM · Fluid