forked from nnja/python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexercise.py
More file actions
29 lines (22 loc) · 668 Bytes
/
exercise.py
File metadata and controls
29 lines (22 loc) · 668 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
# Part 1 - Basic Functions
def add_numbers(x, y):
return x + y
add_numbers(1, 2)
print(f"The product of 1 and 2 is {add_numbers(1, 2)}")
# Function Scope
x = 1
y = 2
def add_numbers(x, y):
print(f"Inside the function, x = {x} and y = {y}")
return x + y
print(f"Outside the function, x = {x} and y = {y}")
print(f"The product of 5 and 6 is {add_numbers(5, 6)}")
# Positional vs Keyword Arguments
def calculate_numbers(x, y, operation="add"):
if operation == "add":
return x + y
elif operation == "subtract":
return x - y
calculate_numbers(2, 3)
calculate_numbers(2, 3, "subtract")
calculate_numbers(2, 3, operation="subtract")