Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2bb769e

Browse files
Create 'Check Armstrong function'
Better code for checking armstrong number and implemented using function Signed-off-by: Kunal Garg <kunalgarg2002@gmail.com>
1 parent 34939f6 commit 2bb769e

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 9,
6+
"metadata": {},
7+
"outputs": [
8+
{
9+
"name": "stdout",
10+
"output_type": "stream",
11+
"text": [
12+
"True\n"
13+
]
14+
}
15+
],
16+
"source": [
17+
"def checkArmstrong(n):\n",
18+
" arr = [int(x) for x in str(n)]\n",
19+
" p = len(arr)\n",
20+
" sum = 0\n",
21+
" for digit in arr:\n",
22+
" sum += digit**p\n",
23+
" return sum\n",
24+
"\n",
25+
"n = int(input())\n",
26+
"print(n==checkArmstrong(n))"
27+
]
28+
}
29+
],
30+
"metadata": {
31+
"kernelspec": {
32+
"display_name": "Python 3.10.4 64-bit",
33+
"language": "python",
34+
"name": "python3"
35+
},
36+
"language_info": {
37+
"codemirror_mode": {
38+
"name": "ipython",
39+
"version": 3
40+
},
41+
"file_extension": ".py",
42+
"mimetype": "text/x-python",
43+
"name": "python",
44+
"nbconvert_exporter": "python",
45+
"pygments_lexer": "ipython3",
46+
"version": "3.10.4"
47+
},
48+
"orig_nbformat": 4,
49+
"vscode": {
50+
"interpreter": {
51+
"hash": "369f2c481f4da34e4445cda3fffd2e751bd1c4d706f27375911949ba6bb62e1c"
52+
}
53+
}
54+
},
55+
"nbformat": 4,
56+
"nbformat_minor": 2
57+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /