Answer to Question #347627 in Python for Hoorain Fatima

Question #347627

Make a Number system convert to convert a number of any number system to another number system. Implement only Binary, Base 5, Octal, Decimal, and Hexa number systems. Converter should be developed in Python language.

1
Expert's answer
2022-06-06T08:58:23-0400
M = int(input("Enter number: "))
N = input("Enter the calculus to which the number belongs (2,5,10,8,16): ")
Z = int(input("Enter the base you want to convert the number to (2,5,10,8,16): "))

if Z == 10:
    def any_base_to_decimal(number, base):
        temp = int(number, base)
        print(temp)


    any_base_to_decimal(str(M), int(N))
else:
    def any_base_to_decimal(number, base):
        temp = int(number, base)
        return temp


    pi = any_base_to_decimal(str(M), int(N))


    def dec_to_base(num, base):
        base_num = ""
        while num > 0:
            dig = int(num % base)
            if dig < 10:
                base_num += str(dig)
            else:
                base_num += chr(ord('A') + dig - 10)
            num //= base

        base_num = base_num[::-1]
        print(base_num)


    dec_to_base(pi, Z)

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