Python program to Convert from Base 2 to 9

num1 = int(input("Insert number to convert: "))
x = num1
base_num = int(input("Choose the base(2-9): "))
if not(2<= base_num <=9):
 quit()
num2 = ''
while num1>0:
 num2 = str(num1%base_num) + num2
 num1 //= base_num
output = "The value of {} in base {} is {}"
print(output.format(x, base_num, num2))

 

 

Output:

Insert number to convert: 7
Choose the base(2-9): 3
The value of 7 in base 3 is 21

Subscribe For Daily Updates

100+ Python Pattern Examplespython pattern examples - star patterns, number patterns