강의

멘토링

커뮤니티

인프런 커뮤니티 질문&답변

sungha46님의 프로필 이미지
sungha46

작성한 질문수

파이썬 무료 강의 (기본편) - 6시간 뒤면 나도 개발자

전달값과 반환값

선생님 질문이 있습니다.

작성

·

192

1

commission, balance =withdraw_naght(blance,500)

print("수수료는 {0}원이며, 잔액은 {1}원 입니다.".format
(commission, balance))

수수료는 100원 이며 , 잔액은 400원 입니다. 라고 문구가 뜨는걸 볼수 있는데  출금 금액을 1000원 이라고 입력을 하니 잔액이 -100원이라고 뜨는데 수수료 포함하여 잔액이 부족할 경우 출금이 완료되지 않았습니다. 라는 문구를 어떻게 하면 만들어 낼수가 있나요 .. 아무리 해도 오류만 나고 만드는 방법을 모르겠습니다.

답변 2

1

sungha46님의 프로필 이미지
sungha46
질문자

감사합니다ㅎㅎ 왜 맨 밑에 else 넣을 생각을 못했는지 

궁금증이 해결 되었습니다.

질문한 코드의withdraw_night 가 withdraw_naght가 되어있었네요ㅎㅎ

1

이렇게하면될것같습니다.

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))
    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)
#balance = withdraw(balance, 2000)
#balance = withdraw(balance, 500)
commission, balance = withdraw_night(balance, 1000)
if balance > 0:
    print("수수료 {0} 원이며, 잔액은 {1} 원입니다.".format(commission, balance))
else:
    print("수수료는 {0} 원이며, 출금이 완료되지 않았습니다.".format(commission))
sungha46님의 프로필 이미지
sungha46

작성한 질문수

질문하기