Answer the question
In order to leave comments, you need to log in
How to convert a number to the binary system consisting of 2 and 5?
The very essence of the problem is in the title. There is some number in the number system consisting of 2 and 5, for example 22. If you convert it to decimal, you get 3. The count starts from 2, that is: 2 - 1; 5 - 2 and so on. I was able to implement it like:
N = int(input())
print(str(int(str(N).replace('2', '0').replace('5', '1'), 2)))
Answer the question
In order to leave comments, you need to log in
Converting a number to a binary string is bin(). The only thing is to tear off the first two characters of the 0b prefix. For more convenient replacement of several characters at once, it is better to use .translate(). As a result, we get:
table = {ord('0'):'2',ord('1'):'5'}
print(bin(N)[2:].translate(table))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question