avatar Bite 299. Base converter

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.

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

 

Login and get coding
go back Intermediate level
Bitecoin 3X

33 out of 36 users completed this Bite.
Will you be Pythonista #34 to crack this Bite?
Resolution time: ~43 min. (avg. submissions of 5-240 min.)
Pythonistas rate this Bite 2.33 on a 1-10 difficulty scale.
» You can do it! 😌

We use Python 3.8