In: Computer Science
This is in python3..
Calculate the Balance - Deposit
If the action is Deposit 'D’, use a deposit function to add funds to the account
Deposit Input
userchoice = input ("What would you like to do?\n") userchoice = 'B' deposit_amount = 200
Deposit Output
What would you like to do? How much would you like to deposit today? Deposit was $200, current balance is $700.25
Customer Deposit
need to add to this program below. use a deposit function to add funds to the account.
import sys# importing the sys library
# account balance
account_balance = float(500.25)
#PPrint the balance
# This is a custom function, it returns the current balance upto 2
decimal places
def printbalance():
print('Your current balance:')
return account_balance
#the function for deposit
#This is a custom function
def deposit():
deposit_amount = float(input("Enter amount to deposit : ")) # takes
in input for deposit amount
balance = account_balance + deposit_amount #calculates
balance
print("Deposit was $%2f, current balance is $%2f"
%(deposit_amount,balance)) # prints out the balance
#function for withdraw
#this is a custom function
def withdraw():
withdraw_amount = float(input("Enter amount to withdraw")) # takes
in the withdraw amount
if(withdraw_amount > account_balance): #checks whether the
amount is more than balance or not
print("$%2f is greater than account balance $%2f\n"
%(withdraw_amount,account_balance)) #if yes then
else:
balance = account_balance - withdraw_amount
print("$%2f was withdrawn, current balance is $%2f" %
(withdraw_amount, balance))
# User Input goes here, use if/else conditional statement to call
function based on user input
userchoice = input("What would you like to do?\n")
if (userchoice == 'D'):
# here deposit function is called
deposit()
elif userchoice == 'W':
# here withdraw function is called
withdraw()
elif userchoice == 'B':
# here printbalance function is called
balance=printbalance()
print('{:.2f}'.format(balance))
else:
# it ends the program execution
sys.exit()
import sys # importing the sys library
# account balance
account_balance = float(500.25)
# PPrint the balance
# This is a custom function, it returns the current balance upto 2 decimal places
def printbalance():
print('Your current balance:')
return account_balance
# the function for deposit
# This is a custom function
def deposit():
# takes in input for deposit amount
deposit_amount = float(
input("How much would you like to deposit today?\n"))
balance = account_balance + deposit_amount # calculates balance
print("Deposit was $%.2f, current balance is $%.2f" %
(deposit_amount, balance)) # prints out the balance
# function for withdraw
# this is a custom function
def withdraw():
# takes in the withdraw amount
withdraw_amount = float(input("Enter amount to withdraw"))
if(withdraw_amount > account_balance): # checks whether the amount is more than balance or not
print("$%2f is greater than account balance $%2f\n" %
(withdraw_amount, account_balance)) # if yes then
else:
balance = account_balance - withdraw_amount
print("$%2f was withdrawn, current balance is $%2f" %
(withdraw_amount, balance))
# User Input goes here, use if/else conditional statement to call function based on user input
userchoice = input("What would you like to do?\n")
if (userchoice == 'D'):
# here deposit function is called
deposit()
elif userchoice == 'W':
# here withdraw function is called
withdraw()
elif userchoice == 'B':
# here printbalance function is called
balance = printbalance()
print('{:.2f}'.format(balance))
else:
# it ends the program execution
sys.exit()
Screenshot of code:
Output: