Python Program to Convert Decimal to Binary Using Recursion

In this example, we will write a recursive function to convert decimal to binary. To better understand this example, make sure you have knowledge of the following tutorials:-

Python Program to Shuffle Deck of Cards

def binary(n):
    if n > 1:
        binary(n // 2)
    print(n % 2, end = '')

# Take decimal number from user
dec = int(input("Enter an integer: "))
binary(dec)

The output of the above program is:-

Enter an integer: 20
10100

SHARE Python Program to Convert Decimal to Binary Using Recursion

You may also like...


Warning: Undefined variable $category in /www/wwwroot/followtutorials.com/wp-content/themes/hueman/sidebar_tutorial.php on line 10

Warning: Trying to access array offset on null in /www/wwwroot/followtutorials.com/wp-content/themes/hueman/sidebar_tutorial.php on line 10

Warning: Attempt to read property "category_parent" on null in /www/wwwroot/followtutorials.com/wp-content/themes/hueman/sidebar_tutorial.php on line 10
Share