Bank Terminal
Programming Basics · Python
TASK
Problem
Given balance, operation `deposit`/`withdraw`, and amount. Deposit adds funds; withdrawal requires amount≤balance. Print new balance or `INSUFFICIENT FUNDS`.
EXAMPLE
Example
1000 withdraw 300
700
LIMITS
Constraints
The input matches the types and format stated in the task; the total input size does not exceed 100,000 values.
LEARN
Theory for this problem
+
`input()` reads data entered by the user. The result of `input()` is initially a string. `int()` converts a numeric string into an integer. `split()` separates one input line into individual values using spaces. The `+` operator adds numbers. The `-` operator subtracts one number from another. Comparison operators `==`, `!=`, `<`, `>`, `<=`, `>=` compare values and produce `True` or `False`. `if` checks a condition and runs its block when the condition is true. `else` runs when the corresponding `if` condition is false. `print()` displays the program result. Print only what the problem statement requires.
**Connection to this task.** An `if` statement chooses a program branch from a Boolean condition. Comparisons produce `True` or `False`, and `elif` lets you test several mutually exclusive cases in order. The expression `b + a` shows how this idea is applied to the task data.
NEED HELP?
Hints
+
['Split logic by operation type first.']
ANSWER
Solution
+
b, op, a = input().split()
b = int(b)
a = int(a)
if op == 'deposit':
print(b + a)
elif a <= b:
print(b - a)
else:
print('INSUFFICIENT FUNDS')