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