I add a function that accepts a parameter when called? And how can I make one of my functions use a return statement to pass data out of the function
How do I add a function that accepts a parameter when called? And how can I make one of my functions use a return statement to pass data out of the function? Where in my script can I make these modifications?
import sys
#account balance
account_balance = float(500.25)
#printbalance function
def balance():
print(“Your current balance:n” + str(account_balance))
#deposit function
def deposit():
global account_balance
deposit_amount = input(“How much would you like to deposit today?n”)
account_balance += float(deposit_amount)
print(“Deposit was $” + str(‘%.2f’ % float(deposit_amount)) + “, current balance is $” + str(account_balance))
#withdraw function
def withdraw():
global account_balance
withdraw_amount = input(“How much would you like to withdraw today?n”)
if float(withdraw_amount) > account_balance:
print(“$” + str(‘%.2f’ % float(withdraw_amount)) + “is greater than your account balance of $” + str(‘%.2f’ % float(account_balance)))
else:
account_balance -= float(withdraw_amount)
print(“Withdrawal amount was $” + str(‘%.2f’ % float(withdraw_amount)) + “, current balance is $” + str(‘%.2f’ % float(account_balance)))
def quit():
print(“Thank you for banking with us.”)
#User Input
userchoice = input (“What would you like to do?n”)
if (userchoice == ‘D’):
deposit ()
if (userchoice ==’B’):
balance()
if (userchoice == ‘W’):
withdraw ()
if (userchoice == ‘Q’):
quit()