You are viewing a single comment's thread. Return to all comments →
def print_formatted(n: int) -> None: n_binary_width: int = len(bin(n)) - 2 for i in range(1, n + 1): n_decimal = str(i) n_octal = oct(i)[2:] n_hexadecimal = hex(i)[2:].upper() n_binary = bin(i)[2:] print( n_decimal.rjust(n_binary_width), n_octal.rjust(n_binary_width), n_hexadecimal.rjust(n_binary_width), n_binary.rjust(n_binary_width), ) if __name__ == "__main__": n = int(input()) print_formatted(n)
Seems like cookies are disabled on this browser, please enable them to open this website
String Formatting
You are viewing a single comment's thread. Return to all comments →