-
Notifications
You must be signed in to change notification settings - Fork 0
/
03_func.py
69 lines (54 loc) · 1.37 KB
/
03_func.py
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# 12 def. 13 return. 14 default arg.
# 15 Variable Scope. 16 Keyword arg. 17 Flexible number of arg. 18 Unpacking arg.
def add(a,b):
sum = a+b
return sum
print(add(1,2))
def beef():
print("good food")
beef()
def bitcoin_to_usd(btc):
amount = btc * 527
print(amount)
bitcoin_to_usd(100)
# 13 return.
def allowed_dating_age(my_age):
girls_age = my_age/2 + 7
return girls_age
print(allowed_dating_age(20))
print(allowed_dating_age(30))
# 14 default arg.
def get_gender(sex = "Unknown"):
if sex is 'm':
sex = "Male"
elif sex is 'f':
sex = "Female"
print(sex)
get_gender('m')
get_gender('f')
get_gender('Other')
get_gender()
# 16 Keyword arg.
def dumb_sentence(name = "Bucky", action = "ate", item = "tuna"):
print(name, action, item)
dumb_sentence()
dumb_sentence("Sally", "farts", "gently")
dumb_sentence(item="awesome")
dumb_sentence(item="awesome", action="si")
# 17 Flexible number of arg.
def add_number(*args):
total = 0
for a in args:
total += a
print(total)
add_number(3)
add_number(3, 32)
add_number(3, 10, 100)
# 18 Unpacking arg.
def health_calculator(age, apples_ate, cigs_smoked):
answer = (100-age) + (apples_ate * 3.5 ) - (cigs_smoked * 2)
print(answer)
health_calculator(10, 1, 1)
data = [27, 20, 1]
health_calculator(data[0], data[1], data[2])
health_calculator(*data) # unpacking data