문제
Whenever somebody goes to an ATM to withdraw or deposit money, a calculation has to be done to keep the person's bank balance correct. Your task in this problem is to do such calculations.
There is a bank rule that says that a customer may not have an overdraft of more than $200, so any withdrawal that would take the balance below –200 must be stopped.
(A minus sign is used to indicate an overdraft, or negative balance).
https://www.acmicpc.net/problem/2975
입력
Input consists of a number of lines, each representing a transaction.
Each transaction consists of an integer representing the starting balance (between –200 and +10,000), the letter W or the letter D (Withdrawal or Deposit), followed by a second integer representing the amount to be withdrawn or deposited (between 5 and 400).
Input will be terminated by a line containing 0 W 0.
출력
Output consists of one line for each line of input showing the new balance for each valid transaction If a withdrawal would take the balance below -200, the output must be the words ‘Not allowed’.
예제
# input
10000 W 10
-200 D 300
50 W 300
0 W 0
# output
9990
100
Not allowed
문제 풀이
while True:
L = list(input().split())
if L == ['0','W','0']:
break
if L[1] == 'W':
ans = int(L[0]) - int(L[2])
print('Not allowed' if ans < -200 else ans)
else:
ans = int(L[0]) + int(L[2])
print(ans)
파이썬을 독학하시는 분들에게 도움이 되길 바라며,
혹 더 좋은 방법이 있거나 오류가 있다면 편하게 말씀 부탁드립니다.