-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction.py
More file actions
48 lines (39 loc) · 1.2 KB
/
function.py
File metadata and controls
48 lines (39 loc) · 1.2 KB
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
# function = A block of reusable code
# place () after the function name to invoke(부르다) it
# 코드를 한 번 쓰고 원할 때마다 호출해서 사용
# name, age은 매개변수(parameter) 순서 고려 해야 함.
def happy_birthday(name, age):
print(f"hello {name}")
print(f"You are {age} years old!")
# 전달 인자(argument) 보낼 수 있음. 순서 고려 해야 함
happy_birthday("Jang hun", 22)
happy_birthday("Jang hun", 24)
happy_birthday("Jang hun", 34)
def display_invoice(username, amount, due_date):
print(f"Hello Nice to meet you {username}")
print(f"Your bill of ${amount:.2f} is due:{due_date}")
display_invoice("Janghun", 42.50, "01/09")
# return = statement used to end a function
# and send a result back to the caller
def add(x,y):
z = x + y
return z
def subtract(x,y):
z = x - y
return z
def multiply(x,y):
z = x * y
return z
def divide(x,y):
z = x / y
return z
print(add(2,3))
print(subtract(2,3))
print(multiply(2,3))
print(divide(2,3))
def create_name(first, last):
first = first.capitalize()
last = last.capitalize()
return first + " " + last
full_name = create_name("yoo", "janghun")
print(full_name)