{ "cells": [ { "cell_type": "markdown", "metadata": { "collapsed": true, "pycharm": { "name": "#%% md\n" } }, "source": "### Write a Python program to print all Disarium numbers between 1 and 100.\n" }, { "cell_type": "code", "execution_count": 2, "outputs": [ { "name": "stdout", "text": [ "Disarium numbers between 1 and 100 are\n1\n2\n3\n4\n5\n6\n7\n8\n9\n89\n" ], "output_type": "stream" } ], "source": "\ndef calculate_length(n):\n length \u003d 0\n while n !\u003d 0:\n length \u003d length + 1\n n \u003d n // 10\n return length\n\n\n# sum_of_digits() will calculates the sum of digits powered with their respective position\ndef sum_of_digits(num):\n remainder \u003d result \u003d 0\n length \u003d calculate_length(num)\n while num \u003e 0:\n remainder \u003d num % 10\n result \u003d result + (remainder ** length)\n num \u003d num // 10\n length \u003d length - 1\n return result\n\n\ndef print_disarium():\n result \u003d 0\n # Displays all disarium numbers between 1 and 100\n print(\"Disarium numbers between 1 and 100 are\")\n for i in range(1, 101):\n result \u003d sum_of_digits(i)\n if result \u003d\u003d i:\n print(i)\n\n\nif __name__ \u003d\u003d \"__main__\":\n print_disarium()\n\n\n\n", "metadata": { "pycharm": { "metadata": false, "name": "#%%\n", "is_executing": false } } } ], "metadata": { "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.6" }, "kernelspec": { "name": "python3", "language": "python", "display_name": "Python 3" } }, "nbformat": 4, "nbformat_minor": 0 }