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