Level 1 : What will be the output of the following Python code?


def a(n):
    if n == 0:
        return 0
    elif n == 1:
        return 1
    else:
        return a(n-1)+a(n-2)
for i in range(0,4):
    print(a(i),end=" ")

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