Δημοσιεύτηκε: 16 Σεπ 2011, 17:39
από parenthesis
Done! Ευχαριστώ πολύ για τις παρατηρήσεις! :thumbup:

Κώδικας: Επιλογή όλων
#! /usr/bin/python3
# Filename: base_converter.py

def convertToBase(toBase, n):
assert (toBase > 1) and (toBase < 37), "the base to convert to must be [2 - 36]!"

foo = ''

while (n > 0):
x = n%toBase
if (x >= 10):
foo = chr(x + 55) + foo
else:
foo = str(x) + foo
n = n//toBase
return foo

try:
num = input('Enter the number you want to convert : ')
base = int(input('Enter the base of the number : '))
assert (base > 2) and (base < 37), "Base must be [2 - 36]!"

new_base = int(input('Now enter the base you want the number to convert to : '))

temp = int(num, base)
new_num = convertToBase(new_base, temp)
print('Number in base -', new_base, ' is :', new_num)

except ValueError:
print("You entered false data!")