Skip to content

Instantly share code, notes, and snippets.

@hoangbits
Created January 9, 2020 05:38
Show Gist options
  • Save hoangbits/759cacf32dc93b4e9458e87eb916ca5a to your computer and use it in GitHub Desktop.
Save hoangbits/759cacf32dc93b4e9458e87eb916ca5a to your computer and use it in GitHub Desktop.
a let b move forward first
def sum_two_numbers(a, b):
return a + b # return result to the function caller
c = sum_two_numbers(3, 12) # assign result of function execution to variable 'c'
def fib(n):
"""This is documentation string for function. It'll be available by fib.__doc__()
Return a list containing the Fibonacci series up to n."""
result = []
a = 1
b = 1
# while a < n:
# result.append(b)
# tmp_var = a
# a = b + a
# b = tmp_var
# return result
# or we could write: because what store in temp should be change first
while a < n:
result.append(a)
tmp_var = b
b = b + a
a = tmp_var
return result
print(fib(10))
# output [1, 1, 2, 3, 5, 8]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment