{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Input a binary number: 10001\n", "The decimal value of the number is 17\n" ] } ], "source": [ "# Write a Python program to convert a binary number to decimal number.\n", "\n", "\n", "b_num = list(input(\"Input a binary number: \"))\n", "value = 0\n", "\n", "for i in range(len(b_num)):\n", "\tdigit = b_num.pop()\n", "\tif digit == '1':\n", "\t\tvalue = value + pow(2, i)\n", "print(\"The decimal value of the number is\", value)\n" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.1" } }, "nbformat": 4, "nbformat_minor": 2 }