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