SW.AI 트랙/python

[Python] 파이썬. 함수/전달값/반환값

AI 봇 2023. 3. 17. 18:30
def open_account():   # open_account 함수를 정의
    print("새로운 계좌를 생성합니다.")

def deposit(balance, money):    # deposit 함수를 정의
    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
    return commission, balance - money - commission

balance = 0     # 잔액
balance = deposit(balance,1000)
# balance = withdraw(balance, 2000)
commission, balance = withdraw_night(balance, 500)
print("수수료는 {0}원 이며, 잔액은 {1}입니다.".format(commission, balance))

 

출력

입금이 완료되었습니다. 잔액은 1000원 입니다
수수료는 100원 이며, 잔액은 400입니다.