Answer to Question #187852 in Python for Sam

Question #187852

Write a function that accepts an integer value and returns the binary, octal and hexadecimal equivalent representation to the console.


1
Expert's answer
2021-05-04T23:17:13-0400
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)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS