Write a function that accepts an integer value and returns the binary, octal and hexadecimal equivalent representation to the console.
def DecimalConversions(n):
print("The binary equivalent of",n,"is",binaryEquivalent(n))
print("The hexadecimal equivalent of",n,"is",hexadecimalEquivalent(n))
print("The octal equivalent of",n,"is",octalEquivalent(n))
def binaryEquivalent(n):
return bin(n).replace("0b", "")
def hexadecimalEquivalent(n):
return hex(n).replace("0x","").upper()
def octalEquivalent(n):
return oct(n).replace("0o","")
if __name__ == '__main__':
num=int(input("Enter an integer:"))
DecimalConversions(num)
Comments
Leave a comment