-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbasic_functions.py
More file actions
38 lines (28 loc) · 896 Bytes
/
basic_functions.py
File metadata and controls
38 lines (28 loc) · 896 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# write Fibonacci series up to n
def fib(n):
'''print Fibonacci series up to n'''
a, b = 0, 1
while a < n:
print (a)
a, b = b, a+b
result = fib(20)
def fib2(n):
'''print Fibonacci series up to n'''
result = []
a, b = 0, 1
while a < n:
result.append(a)
a, b = b, a+b
return result
print(fib2(11))
print ("-"*40)
# Keyword Arguments in a function
def parrot(voltage, state='a stiff', action='voom', type='Norwegian Blue'):
print "-- This parrot wouldn't", action,
print "if you put", voltage, "volts through it."
print "-- Lovely plumage, the", type
print "-- It's", state, "!"
parrot('a thousand', state='pushing up the daisies', action='smell') # 1 positional, 2 keyword
print ("-"*40)
# Unpacking Argument: using * operattor to unpack list or tuple
args = [3,4,5]