Decimal to Binary and Other Bases
Programs with input · Advanced · about 15 min
Read a whole number (0 or more), then a base from 2 to 16, one per line. Print the number written in that base, as 13 in base 2 is 1101. Digits above 9 are the capital letters A to F, so 255 in base 16 is FF. If the base is not from 2 to 16, print Base must be from 2 to 16.
Python's bin() and hex() only cover some bases, so work it out with division.
The prompts inside input() are not checked, only what you print.
Examples
You type:
13 2
The program prints:
13 in base 2 is 1101
You type:
255 16
The program prints:
255 in base 16 is FF
n = int(input("Number: "))
base = int(input("Base (2 to 16): "))
# Print n written in the base
The solution opens after your first Check.