Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions BaseCoverter.py
Original file line number Diff line number Diff line change
@@ -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))
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) |



Expand Down