(1) python 3일차
(2) recap & study
*강의 링크*
python 웹스크래퍼[2.9 ~ 2.11]강의
*Default Parameters*
def say_hello(user_name="anonymous"): #user_name => parameter, default value = (anonymous)
print("Hello",user_name)
say_hello("suhyeok") #Argument = suhyeok
say_hello() #Arguement = none => default value
Parameter(매개변수): 함수 정의할때 사용되는 변수
Argument(인수): 함수를 호출할때 전해주는 변수값
*Return Values*
def tax_calc(money):
return money * 0.35 #return money * 0.35
def pay_tax(tax):
print("thank you for paying", tax)
to_pay = tax_calc("suhyeok") #return value => to_pay variable
pay_tax(to_pay)
그냥 함수를 사용시에는 함수 외부에서 값 사용 불가
따라서, 함수 외부에서 함수 내부 처리된 값을 사용할때 값을 리턴해서 사용
(3) assignment
*조건*
1. get_yearly_revenue (연간 매출 계산)
monthly_revenue (월간 매출)를 인수로 받고,
revenue for a year (연간 매출)를 리턴.
takes monthly_revenue and returns revenue for a year.
2. get_yearly_expenses (연간 비용 계산)
monthly_expenses (월간 비용)를 인수로 받고,
expenses for a year (연간 비용)를 리턴.
takes monthly_expenses returns expenses for a year.
3. get_tax_amount (세금 계산)
profit (이익) 를 인수로 받고,
tax_amount (세금 금액) 를 리턴.
takes profit returns tax_amount.
4. apply_tax_credits (세액 공제 적용)
tax_amount (세금 금액), tax_credits (세액 공제율)를 인수로 받고,
amount to discount (할인할 금액)를 리턴.
takes tax_amount and tax_credits returns amount to discount.
Requirements (요구사항)
get_tax_amount 함수는 if/else 를 사용해야한다.
만약 (if) profit이 100,000 초과이면. 세율은 25% 이다.
아닌 경우에는 (else). 세율은 15% 이다.
*작성 코드*
def get_yearly_revenue(monthly_revenue): #연간 매출 계산
revenue_for_a_year = monthly_revenue * 12 #월간매출 인수 * 12 = 1년
return revenue_for_a_year #연간 매출 리턴
def get_yearly_expenses(monthly_expense): #연간 비용 계산
expense_for_a_year = monthly_expense * 12 #월간비용 인수 * 12 = 1년
return expense_for_a_year #연간 비용 리턴
def get_tax_amount(profit):
tax_amount = 0
if(profit>1000000):
tax_amount += profit * 0.25 #profit이 1000000이상이면 0.25곱해줌
else:
tax_amount += profit * 0.15 #아니면 0.15 곱함
return tax_amount
def apply_tax_credits(tax_amount, tax_credits):
discount = tax_amount * tax_credits #tax_amount*tax_credit = 할인금액
return discount #리턴
*과제 전체 코드*
git link