Created
March 29, 2020 17:54
-
-
Save freeloki/992bc841910df4d9eedbe3a5e6e2cab9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def print_formatted(number): | |
# your code goes here | |
#print("Number is: {}".format(number)) | |
if number >= 1 and number <= 99: | |
num_str = str(bin(number)).replace("0b", "") | |
padding_count = len(num_str) | |
#print("Padding count is: {} ".format(padding_count)) | |
for x in range(1, number + 1, 1): | |
format_data = "{}{}{}{}" | |
# input boyu 1 ise soldan 4 2 ise soldan 3 boşluk bırak | |
# default 2 üç boşluk koyalım. boyu 1 ise bir boşluk daha ekleyelim. | |
bin_x = str(bin(x)).replace("0b", "") | |
if len(bin_x) == 1: | |
bin_x = padding_count * " " + bin_x | |
elif len(bin_x) == 2: | |
bin_x = (padding_count-1) * " " + bin_x | |
elif len(bin_x) == 3: | |
bin_x = (padding_count-2) * " " + bin_x | |
elif len(bin_x) == 4: | |
bin_x = (padding_count-3) * " " + bin_x | |
elif len(bin_x) == 5: | |
bin_x = (padding_count-4) * " " + bin_x | |
elif len(bin_x) == 6: | |
bin_x = (padding_count-5) * " " + bin_x | |
elif len(bin_x) == 7: | |
bin_x = (padding_count-6) * " " + bin_x | |
str_x = str(x) | |
if len(str(x)) == 1: | |
str_x = (padding_count-1)*" " + str_x | |
if len(str(x)) == 2: | |
str_x = (padding_count-2)*" " + str_x | |
hex_x = str(hex(x)).replace("0x", "") | |
hex_x = hex_x.upper() | |
if len(hex_x) == 1: | |
hex_x = padding_count*" " + hex_x | |
elif len(hex_x) == 2: | |
hex_x = (padding_count-1)*" " + hex_x | |
oct_x = str(oct(x)) | |
oct_x = oct_x.replace("0o","") | |
if len(oct_x) == 1: | |
oct_x = padding_count*" " + oct_x | |
elif len(oct_x) == 2: | |
oct_x = (padding_count-1)*" " + oct_x | |
elif len(oct_x) == 3: | |
oct_x = (padding_count-2)*" " + oct_x | |
print(format_data.format(str_x, oct_x, hex_x, bin_x)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment