Q:

# Python | Compute the net amount of a bank account based on the transactions

Given a few transactions (deposit, withdrawal), and we have to compute the Net Amount of that bank account based on these transactions in Python.

Example:

```    Input:
Enter transactions: D 10000
Want to continue (Y for yes): Y
Enter transaction: W 5000
Want to continue (Y for yes): Y
Enter transaction: D 2000
Want to continue (Y for yes): Y
Enter transaction: W 100
Want to continue (Y for yes): N

Output:
Net amount: 6900
```

Program:

``````# computes net bank amount based on the input
# "D" for deposit, "W" for withdrawal

# define a variable for main amount
net_amount = 0

while True:
# input the transaction
str = raw_input ("Enter transaction: ")

# get the value type and amount to the list
# seprated by space
transaction = str.split(" ")

# get the value of transaction type and amount
# in the separated variables
type = transaction [0]
amount = int (transaction [1])

if type=="D" or type=="d":
net_amount += amount
elif type=="W" or type=="w":
net_amount -= amount
else:
pass

#input choice
str = raw_input ("want to continue (Y for yes) : ")
if not (str[0] =="Y" or str[0] =="y") :
# break the loop
break

# print the net amount
print "Net amount: ", net_amount``````

Output

```    Enter transaction: D 10000
want to continue (Y for yes) : Y
Enter transaction: W 5000
want to continue (Y for yes) : Y
Enter transaction: D 2000
want to continue (Y for yes) : Y
Enter transaction: W 100
want to continue (Y for yes) : N
Net amount:  6900
```