Python Error var not defined Im trying to figure out where in my main function or anywhere do I place my return balance

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Python Error var not defined Im trying to figure out where in my main function or anywhere do I place my return balance

Post by answerhappygod »

Python Error var not defined
Im trying to figure out where in my main function or anywhere doI place my return balance and return serviceCharge variable so itbecomes defined.
# Date functionfrom datetime import datetime
def getDate(prompt): while (True):
dateValue = input(prompt) # initializing format with: format ="%d-%m-%Y" format = "%d-%m-%Y" # using try-except to check for truthvalue try: check =bool(datetime.strptime(dateValue, format)) return str(dateValue) except ValueError: # printing result print("\tIncorrect Date format.Try again" )# Function to print the menudef menu(): print('----------------------------------------------------------------------------') print('Transaction Menu') print('----------------------------------------------------------------------------') print('W: Process a check') print('D: Process a deposit') print('E: Exit') print('----------------------------------------------------------------------------')
def output(nameFirst, nameLast,dateEntered, account): print(nameFirst,"'s Transaction Statement") print('----------------------------------------------------------------------------') print('Name: ', nameFirst, nameLast) print("Today's Date:", dateEntered) print('Account Number:',account) print('Current Balance: $%.2f'%balance) print('Accrued service charges:$%.2f'%serviceCharge) print('End of Transaction balance: $%.2f'%(balance -serviceCharge)) print('End of Transaction Summary') print('----------------------------------------------------------------------------')
def userInfo(): print('Enter Your Information') nameFirst = getString('Enter your first name:') nameLast = getString('Enter your last name: ') dateEntered = getDate("Enter today's date asmm-dd-yyyy: ") account = getValue('Enter Account Number: ') initialBalance = getFloatValue('Enter your initialBalance') return nameFirst, nameLast, dateEntered, account,initialBalance
# Function to get a stringdef getString(prompt): value = input(prompt) return value
# Function to get non float valuedef getValue(prompt): while True: try: value =int(input(prompt)) if(value >= 0): returnvalue else: print('\tNegative number entered. Try Again!') except ValueError: print('\tError! NonNumber entered Try Again!')# Funtion to get a float valuedef getFloatValue(prompt): while True: try: value =float(input(prompt)) if(value >= 0): returnvalue else: print('\tNegative number entered. Try Again!') except ValueError: print('\tError! NonNumber entered Try Again!')
# main project funtion def main(): nameFirst, nameLast, dateEntered, account,initialBalance = userInfo() balance = -1 serviceCharge = 0 while balance < 0: balance = initialBalance
# Loop till the user Ends the transition while(True): # Call method to print the menu menu() # input transition type transactionType = getString('Entertransaction type: ') transactionType =transactionType.upper() # Check if iput is valid if not (transactionType == 'W' ortransactionType == 'D' or transactionType == 'E'): print('Invalidchoice') continue # Check for Withdrawal if transactionType == 'W': # Input amount towithdraw amount =getFloatValue('Enter Withdrawl amount: ') print('Processing Checkfor $%.2f'%amount) # Check whether amount issufficient or not if amount >balance: print('Cannot Process Withdrawl of $%.2f'%amount) print('OverDraft: Insufficient Balance') print('Current Balance: $%.2f'%balance) print('OneTime Service charge of: $40.25 for Over Draft Fee') # Incrementservice charge for overdraft serviceCharge += 40.25 print('Accrued service charges: $%.2f'%serviceCharge) # If amount issufficient, program will enter here else: print('Processed Withdrawl for $%.2f'%amount) # Decrementthe balance balance -=amount print('Current Balance: $%.2f'%balance) print('Service charge: $.25 for Withdrawl') # Incrementservice charge serviceCharge += 0.25 print('Accrued service charges: $%.2f'%serviceCharge) # Check for Deposit and inputamount elif transactionType == 'D': amount =getFloatValue('Enter Deposit amount: ') print('Processing Depositof $%.2f'%amount) print('Processed Depositof $%.2f'%amount) # Incement thebalance balance += amount print('Current Balance:$%.2f'%balance) print('Accrued servicecharges: $%.2f'%serviceCharge) # Check for Exit command elif transactionType == 'E': print('Processing end ofTransaction') print('----------------------------------------------------------------------------') # Break the loop break # For incorrect input give amessage else: print('InvalidChoice')
output(nameFirst, nameLast, dateEntered, account)
main()
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply