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