P
P
pythonMyLife2021-06-10 13:48:16
Python
pythonMyLife, 2021-06-10 13:48:16

How not to "crutch" to represent an integer (int) as a ternary string in Python?

There is an integer x, and it needs to be converted to a ternary string.

For example,

to_ternary (6)
# "20"

to_ternary (8)
# "22"

to_ternary (15)
# "120"

Is it possible to crank using standard Python functions/libraries? Like, for example, converting to a binary string:
bin (8)
# "0b1000"

bin (43)
# "0b101011"


Attention, you need to convert the decimal number to the ternary one, and not vice versa

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
alexbprofit, 2021-06-10
@pythonMyLife

int(str(num), 3)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question