Pybites Logo

Base converter

Level: Intermediate (score: 3)

For this challenge, you are going to have write a function to convert a base 10 integer into any base, as long as that base is no lower than 2 and no larger than 36.

Here’s a nice explanation of how it’s traditionally done: Base Conversion Method.

For example:

- 126 converted to base 2 is 1111110

- 126 converted to base 4 is 1332

- 126 converted to base 8 is 176

- 126 converted to base 16 is 7E

If the base is out of that range, the function should raise a ValueError. Raise a TypeError if the number passed in is not an integer.

The returned value should be a string. That’s it, happy coding!