#7-1~7-7
def open_account(): print("새로운 계좌가 생성되었습니다.")
def deposit(balance, money): #입금 print("입금이 완료되었습니다. 잔액은 {0}원 입니다.".format(balance + money)) return balance + money
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): #저녁에출금 commission = 100 #수수료 100원 return commission, balance - money - commission
balance = 0 balance = deposit(balance, 1000) print(balance)
balance = withdraw(balance,100) commission, balance = withdraw_night(balance, 500) print("수수료{0}원이며, 잔액은 {1} 원 입니다.".format(commission,balance))
def profile(name,age,main_lang):
print ("이름 : {0}\t 나이 : {1}\t 주 사용 언어 : {2} "\
.format(name,age,main_lang))
profile("유재석",20,"python")
profile("김태호",20,"jave")
- 같은학교 같은학년 같은 반 같은 수업
def profile(name,age=17, main_lang = 'python'):
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= "python", age = 20)
profile(main_lang= "java",name= '김태호', age = 25) # 순서바꿔도 호출만 되면 알아서 들어감
def profile(name,age,lang1,lang2,lang3,lang4,lang5):
print("이름 {0}\t나이 :{1}\t".format(name,age), end =" ")
print(lang1,lang2,lang3,lang4,lang5)
def profile(name,age,*language):
print("이름 {0}\t나이 :{1}\t".format(name,age), end =" ")
for lang in language:
print(lang,end=" ")
print()
profile("유재석",20, "python", "java","c", "c+","c++","js")
profile("김태호",20, "python", "c++","","","")
함수호출이 끝나면 없어지는 게 지역변수
어디에도 쓰이는 건 전역변수
gun = 10 #전역변수
def checkpoint(soldiers): #경계근무
global gun #위에있는 전역 변수 gun을 사용
gun = gun - soldiers
print("[함수내] 남은 총 : {0}".format(gun))
print("전체 총: {0}".format(gun))
checkpoint(2)
print("남은총 :{0}".format(gun))
def checkpoint_ret(gun, soldiers):
gun = gun - soldiers
print("[함수내] 남은 총 : {0}".format(gun))
return gun
print("전체 총: {0}".format(gun))
gun= checkpoint_ret(gun,2)
print("남은총 :{0}".format(gun))
표준체중을 구하는 프로그램을 작성하시오
함수명 : std_weight
전달값 : 키(height), 성별(gender)
키 175cm 남자의 표준 체중은 67.38Kg 입니다.
def std_weight(height, gender): # 키 m단위(실수), 성별은 남자 / 여자
if gender == '남자':
return height*height*22
else:
return height*height*21
height = 175 # cm
gender = '남자'
weight = round(std_weight(height/100, gender),2) # m단위에서 cm단위로 변환
print("키 {0}cm {1}의 표준 체중은 {2}Kg 입니다.".format(height,gender,weight))