|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "code", |
| 5 | + "execution_count": 16, |
| 6 | + "metadata": {}, |
| 7 | + "outputs": [ |
| 8 | + { |
| 9 | + "name": "stdout", |
| 10 | + "output_type": "stream", |
| 11 | + "text": [ |
| 12 | + "Enter any Number :135\n", |
| 13 | + "Number of Digits are: 3\n", |
| 14 | + "Sum of cube of digits is: 135\n", |
| 15 | + "Its a Dasarium Number\n" |
| 16 | + ] |
| 17 | + } |
| 18 | + ], |
| 19 | + "source": [ |
| 20 | + "import math\n", |
| 21 | + "num=int(input(\"Enter any Number :\" ))\n", |
| 22 | + "temp=num\n", |
| 23 | + "temp1=num\n", |
| 24 | + "counter=0\n", |
| 25 | + "sum=0\n", |
| 26 | + "while(temp>0):\n", |
| 27 | + " d=temp%10\n", |
| 28 | + " counter+=1\n", |
| 29 | + " temp=temp//10\n", |
| 30 | + "print(\"Number of Digits are: \",counter)\n", |
| 31 | + "while(temp1>0):\n", |
| 32 | + " d=temp1%10\n", |
| 33 | + " sum = sum+int(math.pow(d,counter))\n", |
| 34 | + " counter-=1\n", |
| 35 | + " temp1=temp1//10\n", |
| 36 | + "print(\"Sum of cube of digits is: \",sum)\n", |
| 37 | + "if (sum==num):\n", |
| 38 | + " print(\"Its a Dasarium Number\")\n", |
| 39 | + "else:\n", |
| 40 | + " print(\"Its not a Dasarium Number\")" |
| 41 | + ] |
| 42 | + }, |
| 43 | + { |
| 44 | + "cell_type": "code", |
| 45 | + "execution_count": 19, |
| 46 | + "metadata": {}, |
| 47 | + "outputs": [ |
| 48 | + { |
| 49 | + "name": "stdout", |
| 50 | + "output_type": "stream", |
| 51 | + "text": [ |
| 52 | + "Disarium numbers between 1 and 100 are\n", |
| 53 | + "1 2 3 4 5 6 7 8 9 89 " |
| 54 | + ] |
| 55 | + } |
| 56 | + ], |
| 57 | + "source": [ |
| 58 | + "def checkLength(n): \n", |
| 59 | + " length = 0; \n", |
| 60 | + " while(n != 0): \n", |
| 61 | + " length = length + 1; \n", |
| 62 | + " n = n//10; \n", |
| 63 | + " return length; \n", |
| 64 | + "def sumOfnPowerDigits(num): \n", |
| 65 | + " rem = sum = 0; \n", |
| 66 | + " len = checkLength(num); \n", |
| 67 | + " while(num > 0): \n", |
| 68 | + " rem = num%10; \n", |
| 69 | + " sum = sum +int(math.pow(rem,len)) ; \n", |
| 70 | + " num = num//10; \n", |
| 71 | + " len = len - 1; \n", |
| 72 | + " return sum; \n", |
| 73 | + "result = 0; \n", |
| 74 | + "print(\"Disarium numbers between 1 and 100 are\"); \n", |
| 75 | + "for i in range(1, 101): \n", |
| 76 | + " result = sumOfnPowerDigits(i); \n", |
| 77 | + " if(result == i): \n", |
| 78 | + " print(i,end=\" \") " |
| 79 | + ] |
| 80 | + }, |
| 81 | + { |
| 82 | + "cell_type": "code", |
| 83 | + "execution_count": 25, |
| 84 | + "metadata": {}, |
| 85 | + "outputs": [ |
| 86 | + { |
| 87 | + "name": "stdout", |
| 88 | + "output_type": "stream", |
| 89 | + "text": [ |
| 90 | + "Enter any Number :31\n", |
| 91 | + "31 is Happy Number\n" |
| 92 | + ] |
| 93 | + } |
| 94 | + ], |
| 95 | + "source": [ |
| 96 | + "def sqsum(num):\n", |
| 97 | + " res=0\n", |
| 98 | + " rem=0\n", |
| 99 | + " while(num>0):\n", |
| 100 | + " rem = num%10\n", |
| 101 | + " res=res+rem**2 \n", |
| 102 | + " num=num//10\n", |
| 103 | + " return res\n", |
| 104 | + "integer=int(input(\"Enter any Number :\" ))\n", |
| 105 | + "result=integer\n", |
| 106 | + "while result!=1 and result!=4:\n", |
| 107 | + " result=sqsum(result)\n", |
| 108 | + "if result==1:\n", |
| 109 | + " print(n,\"is Happy Number\")\n", |
| 110 | + "else:\n", |
| 111 | + " print(n,\"is not a Happy Number\")" |
| 112 | + ] |
| 113 | + }, |
| 114 | + { |
| 115 | + "cell_type": "code", |
| 116 | + "execution_count": 27, |
| 117 | + "metadata": {}, |
| 118 | + "outputs": [ |
| 119 | + { |
| 120 | + "name": "stdout", |
| 121 | + "output_type": "stream", |
| 122 | + "text": [ |
| 123 | + "List of happy numbers between 1 and 100: \n", |
| 124 | + "1 7 10 13 19 23 28 31 32 44 49 68 70 79 82 86 91 94 97 100 " |
| 125 | + ] |
| 126 | + } |
| 127 | + ], |
| 128 | + "source": [ |
| 129 | + "#isHappyNumber() will determine whether a number is happy or not \n", |
| 130 | + "def isHappyNumber(num): \n", |
| 131 | + " rem = sum = 0; \n", |
| 132 | + "#Calculates the sum of squares of digits \n", |
| 133 | + " while(num > 0): \n", |
| 134 | + " rem = num%10; \n", |
| 135 | + " sum = sum + (rem*rem); \n", |
| 136 | + " num = num//10; \n", |
| 137 | + " return sum; \n", |
| 138 | + "#Displays all happy numbers between 1 and 100 \n", |
| 139 | + "print(\"List of happy numbers between 1 and 100: \"); \n", |
| 140 | + "for i in range(1, 101): \n", |
| 141 | + " result = i; \n", |
| 142 | + "#Happy number always ends with 1 and \n", |
| 143 | + "#unhappy number ends in a cycle of repeating numbers which contains 4 \n", |
| 144 | + " while(result != 1 and result != 4): \n", |
| 145 | + " result = isHappyNumber(result); \n", |
| 146 | + " if(result == 1): \n", |
| 147 | + " print(i,end=\" \"), \n", |
| 148 | + " " |
| 149 | + ] |
| 150 | + }, |
| 151 | + { |
| 152 | + "cell_type": "code", |
| 153 | + "execution_count": 28, |
| 154 | + "metadata": {}, |
| 155 | + "outputs": [ |
| 156 | + { |
| 157 | + "name": "stdout", |
| 158 | + "output_type": "stream", |
| 159 | + "text": [ |
| 160 | + "156 is a harshad number\n" |
| 161 | + ] |
| 162 | + } |
| 163 | + ], |
| 164 | + "source": [ |
| 165 | + "num = 156; \n", |
| 166 | + "rem = sum = 0; \n", |
| 167 | + "n = num; \n", |
| 168 | + "while(num > 0): \n", |
| 169 | + " rem = num%10; \n", |
| 170 | + " sum = sum + rem; \n", |
| 171 | + " num = num//10; \n", |
| 172 | + "if(n%sum == 0): \n", |
| 173 | + " print(str(n) + \" is a harshad number\"); \n", |
| 174 | + "else: \n", |
| 175 | + " print(str(n) + \" is not a harshad number\"); " |
| 176 | + ] |
| 177 | + }, |
| 178 | + { |
| 179 | + "cell_type": "code", |
| 180 | + "execution_count": 30, |
| 181 | + "metadata": {}, |
| 182 | + "outputs": [ |
| 183 | + { |
| 184 | + "name": "stdout", |
| 185 | + "output_type": "stream", |
| 186 | + "text": [ |
| 187 | + "Pronic numbers between 1 and 100: \n", |
| 188 | + "2 6 12 20 30 42 56 72 90 " |
| 189 | + ] |
| 190 | + } |
| 191 | + ], |
| 192 | + "source": [ |
| 193 | + "#isPronicNumber() will determine whether a given number is a pronic number or not \n", |
| 194 | + "def isPronicNumber(num): \n", |
| 195 | + " flag = False; \n", |
| 196 | + " for p in range(1, num+1): \n", |
| 197 | + " if((p*(p+1)) == num): \n", |
| 198 | + " flag = True; \n", |
| 199 | + " break; \n", |
| 200 | + " return flag; \n", |
| 201 | + "print(\"Pronic numbers between 1 and 100: \"); \n", |
| 202 | + "for i in range(1, 101): \n", |
| 203 | + " if(isPronicNumber(i)): \n", |
| 204 | + " print(i,end=\" \"), " |
| 205 | + ] |
| 206 | + } |
| 207 | + ], |
| 208 | + "metadata": { |
| 209 | + "kernelspec": { |
| 210 | + "display_name": "Python 3", |
| 211 | + "language": "python", |
| 212 | + "name": "python3" |
| 213 | + }, |
| 214 | + "language_info": { |
| 215 | + "codemirror_mode": { |
| 216 | + "name": "ipython", |
| 217 | + "version": 3 |
| 218 | + }, |
| 219 | + "file_extension": ".py", |
| 220 | + "mimetype": "text/x-python", |
| 221 | + "name": "python", |
| 222 | + "nbconvert_exporter": "python", |
| 223 | + "pygments_lexer": "ipython3", |
| 224 | + "version": "3.6.9" |
| 225 | + } |
| 226 | + }, |
| 227 | + "nbformat": 4, |
| 228 | + "nbformat_minor": 4 |
| 229 | +} |
0 commit comments