🍇🍇CHALLENGE🍉🍉. IT'S ALL ABOUT BASES. Objective: 👉 Write aprogram, that convert a number in a certain base to another base | SoloLearn: Learn to code for FREE!


🍇🍇CHALLENGE🍉🍉. IT'S ALL ABOUT BASES. Objective: 👉 Write aprogram, that convert a number in a certain base to another base

FORMAT : 👉Your program should take three input : ☝The number to be converted ✌ The base of the number to be converted 👌The base to which you wish your number to be converted to. Example : number : 2E base : 16 tobase: 5 Output =141 ---- number: 3245 base: 6 tobase: 9 Output = 1022 LIMITATIONS : 👉Don't use module/built function that converts, example bin(),hex() Here's mine: https://code.sololearn.com/cRFGPQn2VEts/?ref=app The first 10 correct codes will reposted by me and get best answer mark. DO IT

11/23/2017 8:49:35 AM

Justine Ogaraku

10 Answers

New Answer


Here's : https://code.sololearn.com/cqWgBIq0sU31/?ref=app


@Justine Hahaha 👍 There will be codes in other languages, be patient... 😉


Hmmmm..... What's happening here, two correct Java code. I'm envious of Java already 😂.


@Vadim hmmmmmm...... I'll be expecting it 😁


My try.. OOP style, creates base objects and can perform some operations.. feel free to test and implement any operator overloading! Hope you enjoy it! https://code.sololearn.com/cLlqQ5bQ0Ztt/?ref=app


Since Java is positioned as a cross-platform language, I did not go through an easy way of 10 + c - 'a'. Because I did not expect the letters in the code table to go in a row. https://code.sololearn.com/csm9e4p4r307/?ref=app


@Justine. I'll try to translate my code into C##. Patience...


Here I and in C# was trained. https://code.sololearn.com/cg4HK8PyxrHy


Hmmm... what happens past base 36 when all numbers/letters get used up?


Here's my try in Python, https://code.sololearn.com/cmPzpa1CAH9O/ The code logic is pretty much up to line 28, everything else's basically making use of it. Samples are randomly generated as user input in SL is annoying. Also, literals and integers' signedness is not taken into account at all, but such addition to the code should be trivial. By the way @Justine, your code accepts invalid input with regards to the submitted source base. As in, if we input the string '1Z' and its source base as 14, it continues execution generating erroneous output, like 49 if the output base is 10, when in reality the character 'Z' is out of the base 14 range. Mine, on the other hand, raises a "ValueError('substring not found')" exception (by the `str.index` method) since I also slice my `BASE36` string to the according base parameter (line 21), which I deliberately let propagate as it's enough to signal out of base-range literals. (Sorry for the TL;DR wall of text :) )