Decimal to Octal

    0

    0

    Mahendra Kumar

    beginnerbasicMaths

    Python Program to Convert Decimal to Octal

    def DecimalOctal(num):
        octal = [0] * 100
        # counter for octal number array
        i = 0
        while (num != 0):
            # store remainder in octal array
            octal[i] = num % 8
            num = int(num / 8)
            i += 1
        # print octal number array in reverse order
        for j in range(i - 1, -1, -1):
            print(octal[j], end='')
    # take inputs
    num = int(input('Enter a decimal number: '))
    # calling function and display result
    print('Octal value: ', end='')
    DecimalOctal(num)
    
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    Legal
    • Security
    • Privacy Policy
    • Code Privacy
    • Terms of Service
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.