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