ν¨μ
def deposit(balance, money):
print("μ
κΈμ΄ μλ£λμμ΅λλ€. μμ‘μ {0}μμ
λλ€".format(balance+money))
return balance + money
μ λ¬κ°κ³Ό λ°νκ°
def deposit(balance, money):
print("μ
κΈμ΄ μλ£λμμ΅λλ€. μμ‘μ {0}μμ
λλ€".format(balance+money))
return balance + money
# ν¨μ λ΄μμ μ΄λ€ λμμ νκ³ λμ νΉμ 'κ°'μ λ°νν΄μ€ λ return μ μ¬μ©ν©λλ€.
# κ·Έλ¬λ©΄ κ·Έ ν¨μλ₯Ό νΈμΆνλ κ³³μμ λ°νλ°μ return κ°μ λ³μμ λ΄μμ μ΄νμ μ¬μ©μ΄ κ°λ₯ν©λλ€.
def withdraw(balance, money): #μΆκΈ
if balance > money: #μμ‘μ΄ μΆκΈλ³΄λ€ λ§μΌλ©΄
print("μΆκΈμ΄ μλ£λμμ΅λλ€. μμ‘μ {0}μ μ
λλ€".format(balance - money))
return balance - money
else:
print("μΆκΈμ΄ μλ£λμ§ μμμ΅λλ€. μμ‘μ {0}μμ
λλ€".format(balance))
return balance
def withdraw_night(balance, money): #μ λ
μ μΆκΈ
commision = 100 #μμλ£ 100μ
return commision, balance - money - commision
balance = 0 #μμ‘
balance = deposit(balance, 1000)
balance = withdraw(balance, 600)
commision, balance= withdraw_night(balance, 200)
print("μμλ£ {0}μμ΄λ©°, μμ‘μ {1}μ μ
λλ€.".format(commision,balance))
ν€μλκ°
def profile(name, age, main_lang):
print("μ΄λ¦ : {0}\tλμ΄ {1}\t μ£Ό μ¬μ© μΈμ΄: {2}"\
.format(name, age, main_lang))
profile("μ μ¬μ", 20, "νμ΄μ¬")
profile("μ μ¬μ", 25, "μλ°")
#κ°μ νκ΅ κ°μ λ° κ°μ μμ
def profile(name, age=17, main_lang="python"): #λ§μ½ λμ΄, μΈμ΄ μ λ¬λ°μ§ μμμ λ κΈ°λ³Έμ μΌλ‘ 17κ³Ό νμ΄μ¬ νΈμΆλ°μ
print("μ΄λ¦ : {0}\tλμ΄ {1}\t μ£Ό μ¬μ© μΈμ΄: {2}"\
.format(name, age, main_lang))
profile("μ μ¬μ")
profile("κΉννΈ")
κΈ°λ³Έκ°
μμκ° λ€μμ¬λ ν¨μλ₯Ό νΈμΆν μ μλ€.
#μμκ° λ€μμ¬λ ν¨μ νΈμΆν μ μμ
def profile(name, age, main_lang):
print(name, age, main_lang)
profile(name="μ μ¬μ",main_lang="νμ΄μ¬",age=20)
κ°λ³μΈμ
μλμ ν¨μλ langμ κ°μλ₯Ό μΌμΌμ΄ λ§μΆ°μ μμ±ν΄μ€μΌνλ λ²κ±°λ‘μμ΄ μλ€.
def profile(name, age, lang1, lang2, lang3, lang4, lang5):
print("μ΄λ¦ : {0}\tλμ΄ : {1}\t".format(name, age),end=" ") #end=" "λ νλ¦°νΈλ¬Έ λλ ν μ€λ°κΏ νμ§X
print(lang1, lang2, lang3, lang4, lang5)
λ°λΌμ, κ°λ³μΈμλ₯Ό μ¬μ©νλ€! end=" "λ printλ¬Έ λλλ ν λ°κΏ μνλ€λ κ²
def profile(name, age, *language):
for lang in language:
print(lang,end=" ")
print()
profile("μ μ¬μ",20, "python", "java", "C", "C++", "C#")
profile("κΉννΈ",20, "kotlin", "swift")
μ§μλ³μμ μ μλ³μ
gun = 10 #μ μλ³μ
def checkpoint(soldiers): #κ²½κ³κ·Όλ¬΄
global gun #μ μ곡κ°μ μλ gun μ¬μ©
gun = gun - soldiers
print("[ν¨μ λ΄] λ¨μ μ΄ : {0}".format(gun))
checkpoint(2) #2λͺ
μ΄ κ²½κ³κ·Όλ¬΄ λκ°
print("λ¨μ μ΄ : {0}".format(gun))
μ μλ³μ μ¬μ©μ κΆμ₯λμ§ μλλ€. ν¨μκ° λ³΅μ‘ν΄μ§λ©΄ νλ€κΈ° λλ¬Έμ!
νλΌλ―Έν°λ‘ λ°μ μ¬μ©νλ κ²μ κΆμ₯! λ°λΌμ μλμ κ°μ΄ μ°λ©΄ μ’μ!
#μ μλ³μ μ°λ κ² κΆμ₯λμ§ μμ, νλΌλ―Έν°λ‘ λ°λ κ² κΆμ₯
def checkpoint_ret(gun, soldiers):
gun = gun - soldiers
print("[ν¨μ λ΄] λ¨μ μ΄ : {0}".format(gun))
return gun
gun = checkpoint_ret(gun, 1)
print("μ 체 μ΄ : {0}".format(gun))
ν΄μ¦
νμ€ μ²΄μ€μ ꡬνλ νλ‘κ·Έλ¨ μμ±νμ¬λΌ
*νμ€ μ²΄μ€: κ° κ°μΈμ ν€μ μ λΉν 체μ€
(μ±λ³μ λ°λ₯Έ 곡μ)
λ¨μ : ν€ * ν€ * 22
μ¬μ : ν€ * ν€ * 21
쑰건1: νμ€ μ²΄μ€μ λ³λμ ν¨μ λ΄μμ κ³μ°
* ν¨μλͺ
: std_weight
* μ λ¬κ°: ν€(height), μ±λ³(gender)
쑰건2: νμ€ μ²΄μ€μ μμμ λμ§Έμ리κΉμ§ νμ
(μΆλ ₯ μμ )
ν€ 175cm λ¨μμ νμ€ μ²΄μ€μ 67.38kgμ λλ€.
λ΄κ° νΌ κ²
def std_weight(height, gender):
if gender == "λ¨μ":
weight = round(height * height * 22,2)
else:
weight = round(height * height * 21,2)
print("ν€ {0}cm {1}μ νμ€ μ²΄μ€μ {2}kgμ
λλ€.".format(height, gender, weight))
ν΄μ€
def std_weight(height, gender) : #ν€ m λ¨μ, μ±λ³ "λ¨μ"/"μ¬μ"
if gender == "λ¨μ":
return height * height * 22
else:
return height * height * 21
height = 174 #çm λ¨μ
gender = "λ¨μ"
weight = round(std_weight(height/100,gender),2)
print("ν€ {0}cm {1}μ νμ€ μ²΄μ€μ {2}kgμ
λλ€.".format(height, gender, weight))