A positional system1 is a numeral system2 in which a number is represented by a range of symbols — usually, Arabic numbers and lowercase letters are used — of which the position based on the radix determines the contribution of the number. The usual radix is ten. It is doubtful that this radix stems from the fact that people counted on their fingers. A number like 1234 than means: $$1 \times 1000 + 2 \times 100 + 3 \times 10 + 4 \times 1$$. The position of the digit determines the contribution in squares of the radix 10 to the number.
An integer $$x$$ is expressed in the decimal positional system as a sequence of terms of powers of another integer: the radix $$a$$: \[x = \sum_{i=0}^kx_ia^i\] of \[x = x_ka^k + \ldots + x_2a^2 + x_1a^1 + x_0a^0\] to the co-ordinates $$x_i \in \mathbb{N}$$ of which applies that $$0 \leq x_i < a$$. In the $$a$$-numbered system, $$x$$ is then represented as a sequence of symbols: \[x_k\ldots x_2x_1x_0\] The coefficients $$x_i$$ form the symbols of that number. The leftmost symbol $$x_k$$ is the coefficient of the highest power of the radix, the rightmost $$x_0$$ is the coefficient of the unities (the 0th power of the radix).
As such, the number $$1234_{10}$$ is written as $$3412_7$$ in the 7-numbered system, because: \[1234_{10} = 3 \times 7^3+ 4 \times 7^2 + 1 \times 7^1 + 2 \times 7^0\]
Write a function positionalsystem that converts the representation of a number in the positional system to a given radix $$a_1$$ to the representation of that same number in the positional system of an other radix $$a_2$$. Give this function the three parameters below:
a string with the representation of a number in a positional system with given radix $$a_1$$
the radix $$a_1$$
the radix $$a_2$$
def positionalsystem(number, radix1, radix2)
The function must print a string that represents the number in the positional system with radix $$a_2$$. You may assume that $$0 < a_1, a_2 \leq 36$$. For the string representation of numbers in a positional system, three accepted symbols are used:
the values 0, 1, …, 9 are represented by the Arabic digits '0', '1', …, '9'
the values 10, 11, …, 35 are represented by the letters 'a', 'b', …, 'z'
>>> positionalsystem('1234', 10, 7)
'3412'
>>> positionalsystem('1234', 10, 16)
'4d2'
>>> positionalsystem('4d2', 16, 10)
'1234'
>>> bin(1234)[2:] == positionalsystem('1234', 10, 2)
True
>>> oct(1234)[2:] == positionalsystem('1234', 10, 8)
True
>>> hex(1234)[2:] == positionalsystem('1234', 10, 16)
True