Level 9 : Determine whether the given number is an Armstrong number or not.


num = 23

if num == sum(int(digit) ** 3 for digit in str(num)):
    print(f"{num} is an Armstrong number")
else:
    print(f"{num} is not an Armstrong number")

Author: Pavan | Tags: mathematics | 1859+ Python FAQs | Share
identity-operator | assert | copy | append | class | class-and-inheritance | application | anchors-(^,-$) | call | benefit | collection | built-in | assignment-operator | __init_subclass__ | assignment-operators | built-in-modules | binary-operation | bitwise-operator | class-decorators | advanced-file-operations | attribute | bitwise-operator | built-in-function | arithmetic-operation | choice | collections | bitwise | basic | aggregating-data-with-functools.reduce() | array | binary | comparison | inherit | class-and-object | exception | booleans | asyncio | generators | command-line-parsing | implementation | for | __future__ | asyncio-module | filter-function | comment | heap-memory | filtering-and-indexing | immutable-data-type | functions | async | encoding | fabs-function | generator | global-variable | else-statement | join | escape-operator | classes | input-function | global-variable | print | recurssion | syntax-error | installation | arithmetic-expression | dicts | global | counter | exception-handling | introduction-to-multiprocessing | sum-function | comprehension | def | arbitrary-arguments-(*args,-**kwargs) | boolean-and-non-boolean | built-in-function | data-structures-in-python | indexing:-loc-vs-iloc | default-mutable-argument | syntaxerror | regular-expression | string-method | exponentiation | class-and-instance-variable | strings | __all__-attribute | string-formatting | center | access-modifier | decimal | sorted | creating-and-starting-threads | data-type | single-inheritance | slicing | string-concatenation | test-discovery | data-type-conversions | lambda-functions | head-and-tail | list-join | dataframe-and-series-objects | boolean | set-operation | boolean-masking | immutability | sorting | sys-module | dictionary-comprehensions | sys | swapping | regular-expressions | data-type | library | sum() | data-structure | invalid-list | set | compute | format | round | data-types | rollback | list-slicing | random-function | reading-and-writing-large-files-efficiently | software-design | overflow | import-method | recursion | handling-missing-values-(fillna,-dropna) | matrix | higher-order-function | control-statement | python_version | iterable | staticmethod | data-structures | list-comprehension | regex | round-function | loop | creating-custom-modules | dictionary-methods | string-methods | datatype | multiple-except-blocks | object-attribute | feature | gil | identity-operator | function-argument | sorting-and-ranking | integer | min-max-function | lambdas | default-arguments | intering | list-comprehension | string-formatting | debugging | min-function | max-min | indexing | list-comprehensions | data-structure | module | control-flow | sets | lambda | string-manipulation | list-methods-and-slicing | file-handling | error-handling | global-keyword | string-iteration | context-manager | slice | directory-operations | math-copysign | using-os-and-pathlib-modules | floating-point-precision | counter-function | operand | syntax | list-method | thread-synchronization | nested-loop | deep-copy | namedtuple | pandas | operator | pep | match | mysql | complex-number | tuple-methods | exception-handling | else | docstring | expression | file | operator-or | error | factorial-function | with-statement | difference-between-threads-and-processes | syntax-error | map-function | literal-characters-and-special-characters | loop-control | defining-functions | frozenset | multiprocessing | function-and-scope | quantifiers-(*,-+,-?,-{}) | loops | descriptors | type_conversion | encapsulation | zip | using-the-threading-module | string | expand-tab | file_handling | method | formatting-with-strftime | version-check | python-operators | goto-function | string-method | function | parsing-with-strptime | condition | statement | matplotlib | threading | static-method | data_structure | touples | datetime | using-else-and-finally | lists | string-slicing | iterators | string-slicing | introduction-to-python | floats | odd-number | tuple-unpacking | zip-function | key-value-pairs | enumerate() | python-django | conditional-statement | complex | range | scientific-notation | error-handling | memory-management | conditional-statements | design-principle | dictionary | control-flow | filter | opening-files-(open()) | operations | multiple-inheritance | python-syntax-and-structure | thread-safe-data-structures-(queue.queue) | constructor | generators-in-python | functional-programming | datetime.date,-datetime.time,-datetime.datetime | operators | matrix-list-comprehension | math | reading:-read(),-readline(),-readlines() | conditional-statement | conversion | shallow-copy | return-statement | functional-programming | id-function | mutable | typeerror | formal-and-actual-parameter | input-function | introduction-to-threads | input | stack | precedence-and-associativity | operator-overloading | virtual-environment | decorator | while-loops | parameter | iterator | dictionaries | working-with-file-paths | tuples | destructor | init | identity-operators-(is,-is-not) | namespace | list | thread | using-assertions-(assertequal,-assertraises) | list-vs-tuple | logical-operation | type-conversion | keyword | interpreter | inheritance | python | time-series-with-pandas | identifier | raise | int | lambda-function | variable | integers | indentation | joining-and-merging-dataframes | numpy | list-indexing | python-repl | precedence | list-operation | magic-method | update | list,-set,-and-dictionary-comprehensions | name-mangling | virtual-environment | method-overloading | type-conversion | random | numeric | working-with-binary-files-(rb,-wb) | reading-and-writing-files | unit-testing | python-module | raise-statement | pseudocode | pass | while-else-loop | pickling--unpickling | postfix | multithreading | package-management | print-statement | oops | oop | type-conversion-and-casting | working-with-temporary-files-using-tempfile | while-loop | using-yield-in-functions | membership-operators-(in,-not-in) | polymorphism | using-join()-and-is_alive()-methods | version | zfill-function | mathematics | objects | tuple | list-mutation | overriding-methods | methods | loop-control-statements | operator-and | memory | managing-directories-with-os-and-shutil | python-history | walking-through-directories-using-os.walk() | writing:-write(),-writelines() | mapping-function | multiple-inheritance | using-map()-for-transformations | logical-operator | why-use-multiprocessing-over-threading?-(gil) | logical-operators | mathematical-function | file-handling | while-and-for-loop | logical-operator | using-lists-as-stacks | working-with-dates-and-times | yield | turtle | split ...