Last active
August 19, 2021 18:55
-
-
Save r14152/c7b5bd687c65b41cb64dfdc722449f36 to your computer and use it in GitHub Desktop.
format the string from hackerank
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 getLongestNumber(number): | |
binSize = str(len(bin(number))-2) | |
finalStringPrint = ("%"+binSize+"s %"+str(binSize) | |
+"s %"+str(binSize)+"s %"+str(binSize)+"s") | |
return finalStringPrint | |
def print_formatted(number): | |
printStateMent = getLongestNumber(number) | |
#print(printStateMent) | |
for i in range(0,number): | |
print(printStateMent %(i+1,oct(i+1)[2:], | |
(hex(i+1)[2:]).upper(),bin(i+1)[2:])) | |
if __name__ == '__main__': | |
n = int(input()) | |
print_formatted(n) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment