A PHP Error was encountered

Severity: 8192

Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Filename: libraries/Filtered_db.php

Line Number: 23

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

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

0

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

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now