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