Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def FormattedNumber(N):
- NBin = bin(N)
- l = len(NBin) - 1
- for i in range(1, N+1):
- DEC = i
- AuxOCT = list(oct(i))
- AuxHEX = list(hex(i))
- AuxBIN = list(bin(i))
- AuxOCT.pop(0)
- AuxOCT.pop(0)
- OCT = ""
- for j in AuxOCT:
- OCT += j
- AuxHEX.pop(0)
- AuxHEX.pop(0)
- HEX = ""
- for j in AuxHEX:
- HEX += j
- AuxBIN.pop(0)
- AuxBIN.pop(0)
- BIN = ""
- for j in AuxBIN:
- BIN += j
- HEX = HEX.replace("a","A")
- HEX = HEX.replace("b","B")
- HEX = HEX.replace("c","C")
- HEX = HEX.replace("d","D")
- HEX = HEX.replace("e","E")
- HEX = HEX.replace("f","F")
- DEC_SEP = ""
- OCT_SEP = ""
- HEX_SEP = ""
- PRE_SEP = ""
- for j in range (l - len(OCT)):
- DEC_SEP += " "
- for j in range (l - len(HEX)):
- OCT_SEP += " "
- for j in range (l- len(BIN)):
- HEX_SEP += " "
- EQ = len(str(N)) - len(str(DEC))
- for j in range (EQ + 3):
- PRE_SEP += " "
- print(PRE_SEP,end="")
- print(DEC, end=DEC_SEP)
- print(OCT, end=OCT_SEP)
- print(HEX, end=HEX_SEP)
- print(BIN)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement