Compute Net Amount Bank Account Transaction
- In this Python exercise, write a Python program computes the amount of a banking account transaction based on a transaction from the user input selection. The user input whether the transaction is a deposit or withdraw. Obviously this is not a real bank transaction so this exercise is to keep it simple by just creating transaction types of deposit and withdraw.
Source Code:
import random
amount = 100
loggedOn = True
while loggedOn:
selection = int(input("\nSelect 1 for Deposit, \n2 for Withdraw \n3 for Exit \nSelect any option:"))
if not selection:
break
if selection == 1:
deposit = float(input("\nHow much will you deposit? "))
amount += deposit
print(f"\nDeposit in the amount of ${format(deposit, '.2f')} ")
print(f"Bank account balance ${format(amount, '.2f')} ")
elif selection == 2:
withdraw = float(input("\nHow much will you withdraw? "))
if amount >= withdraw:
amount -= withdraw
print(f"\nWithdraw in the amount of ${format(withdraw, '.2f')} ")
print(f"Bank account balance ${format(amount, '.2f')} ")
else:
print("\nThis transaction can not be processed.")
print("Withdraw amount is greater than bank account amount. ")
else:
loggedOn = False
print("\nTransaction number: ", random.randint(10000, 1000000))
Comments
Post a Comment