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