We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- Python
- Strings
- String Formatting
- Discussions
String Formatting
String Formatting
Sort by
recency
|
1775 Discussions
|
Please Login in order to post a comment
This is my solution - def print_formatted(number): length = len(bin(number)[2:]) for num in range(1,number+1): print(str(num).rjust(length), oct(num)[2:].rjust(length),
hex(num).upper()[2:].rjust(length), bin(num)[2:].rjust(length))
def print_formatted(number): width = len(bin(number)[2:]) for i in range(1, number+1): deci = str(i) bina = bin(i)[2:] octa = oct(i)[2:] hexa = hex(i)[2:].upper() print(deci.rjust(width), octa.rjust(width), hexa.rjust(width), bina.rjust(width))
if name == 'main': n = int(input()) print_formatted(n) `
def print_formatted(number): width = len(bin(number)[2:]) for i in range(1, number+1): deci = str(i) bina = bin(i)[2:] octa = oct(i)[2:] hexa = hex(i)[2:].upper() print(deci.rjust(width), octa.rjust(width), hexa.rjust(width), bina.rjust(width))
if name == 'main': n = int(input()) print_formatted(n)