Skip to content

Commit 9616df4

Browse files
updated
1 parent 875956f commit 9616df4

8 files changed

Lines changed: 74 additions & 13 deletions

File tree

31-functions/create_name.py

Lines changed: 0 additions & 12 deletions
This file was deleted.

31-functions/net_price.py

Whitespace-only changes.

32-default-arguments/count.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# default arguments = A default value for certain parameters
2+
# default is used when that argument is omitted
3+
# make your functions more flexible, reduce # of arguments
4+
# 1. positional, 2. DEFAULT, 3. keyword, 4. arbitrary
5+
6+
7+
import time
8+
9+
def count(end, start=0):
10+
for x in range(start,end+1):
11+
print(x)
12+
time.sleep(1)
13+
print("DONE")
14+
15+
count(30,10)
16+
17+

32-default-arguments/main.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,18 @@
11
# default arguments = A default value for certain parameters
22
# default is used when that argument is omitted
33
# make your functions more flexible, reduce # of arguments
4-
# 1. positional, 2. DEFAULT, 3. keyword, 4. arbitrary
4+
# 1. positional, 2. DEFAULT, 3. keyword, 4. arbitrary
5+
6+
7+
# default arguments must be placed after positional arguments
8+
# example: def func(pos1, pos2, default1=5, default2="hello")
9+
10+
def net_price(price, tax_rate=0.08, discount=0):
11+
"""Calculate the net price of an item after tax and discount"""
12+
final_price = price + (price * tax_rate) - discount
13+
return final_price
14+
15+
# print(net_price(500))
16+
17+
18+
print(net_price(500,0.1))

33-keyword-arguments/end.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# default arguments = A default value for certain parameters
2+
# default is used when that argument is omitted
3+
# make your functions more flexible, reduce # of arguments
4+
# 1. positional, 2. DEFAULT, 3. keyword, 4. arbitrary
5+
6+
7+
for x in range(1,11):
8+
print(x,end=" ")

33-keyword-arguments/get_phone.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# default arguments = A default value for certain parameters
2+
# default is used when that argument is omitted
3+
# make your functions more flexible, reduce # of arguments
4+
# 1. positional, 2. DEFAULT, 3. keyword, 4. arbitrary
5+
6+
7+
def get_phone(country, area, first, last):
8+
return f"{country}-{area}-{first}-{last}"
9+
10+
# phone_num = get_phone(1,547,000,0000)
11+
12+
phone_num = get_phone(country="+1",area="547",first="000",last="0000")
13+
14+
print(phone_num)

33-keyword-arguments/main.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# default arguments = A default value for certain parameters
2+
# default is used when that argument is omitted
3+
# make your functions more flexible, reduce # of arguments
4+
# 1. positional, 2. DEFAULT, 3. keyword, 4. arbitrary
5+
6+
def hello(greeting, title, first, last):
7+
print(f"{greeting} {title} {first} {last}")
8+
9+
# hello("Hello", "Mr", "Spongebob", "Squarepants" )
10+
11+
hello("Hello", "Mr", first="Spongebob", last="Squarepants" )
12+
13+

33-keyword-arguments/seperate.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# default arguments = A default value for certain parameters
2+
# default is used when that argument is omitted
3+
# make your functions more flexible, reduce # of arguments
4+
# 1. positional, 2. DEFAULT, 3. keyword, 4. arbitrary
5+
6+
7+
print("1", "2", "3", "4", "5", sep="-")

0 commit comments

Comments
 (0)