diff --git a/BaseCoverter.py b/BaseCoverter.py new file mode 100644 index 0000000..b75e991 --- /dev/null +++ b/BaseCoverter.py @@ -0,0 +1,28 @@ +# Grant - grantslone + +def base_conv(num, frombase, tobase): + try: + frombase = int(frombase) + tobase = int(tobase) + num_dec = int(num, frombase) + b = [2,8,10,16] + for x in [frombase, tobase]: + if x not in b: + raise ValueError + except ValueError: + return "ValueError: Please use a valid number and/or base" + + base_dict = { + 2: ':b', + 8: ':o', + 10: ':d', + 16: ':x' + } + return "Converting " + str(num_dec) + " from Base(" + str(frombase) + ") to Base(" + str(tobase) + ") \nResult: "\ + + ('{' + base_dict[tobase] + '}').format(num_dec) + +num = input("Enter a number: ") +fbase = input("Please enter a base to start from [2, 8, 10, 16]: ") +tbase = input("Please enter a base you wish to convert to [2, 8, 10, 16]: ") + +print(base_conv(num, fbase, tbase)) \ No newline at end of file diff --git a/README.md b/README.md index 2b6fee7..45e1567 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,8 @@ Thanks! | [TicTacToe.py](https://github.com/accakks/Simple-Programs-in-Python/blob/master/TicTacToe.py) | 2 Player Tic Tac Toe | [Aakanksha](https://github.com/accakks) | | [RockPaperScissors.py](https://github.com/accakks/Simple-Programs-in-Python/blob/master/RockPaperScissors.py) | Rock Paper Scissors with Computer | [Aakanksha](https://github.com/accakks) | | [countCharacter.py](https://github.com/accakks/Simple-Programs-in-Python/blob/master/countCharacter.py) | Counts number of times each character occurs in the input string. | [Aakanksha](https://github.com/accakks) | -| [PasswordGenerator.py](https://github.com/Renderer-RCT2/Simple-Programs-in-Python/blob/master/PasswordGenerator.py) | Generates random passwords with an assortment of characters. | [Professor Renderer](https://github.com/Renderer-RCT2) +| [BaseConverter.py](https://github.com/grantslone/Simple-Programs-in-Python/blob/master/BaseConverter.py) | Converts an input number from one base to another. | [grantslone](https://github.com/grantslone) | +| [PasswordGenerator.py](https://github.com/Renderer-RCT2/Simple-Programs-in-Python/blob/master/PasswordGenerator.py) | Generates random passwords with an assortment of characters. | [Professor Renderer](https://github.com/Renderer-RCT2) |