Homework assignment description:
'Assignment - 'Objectives:
1. Write the main function by following the flowchart provided.
2. Watch the associated video tutorial “Creating Visio Flowcharts” and study the “Designing a Program – BMI” example program.
3. Draw the flowcharts for the withdrawal, deposit, invalid code, and display new balance functions.
4. Learn how to design and code decision statements.
5. Validate the transaction code and transaction amount.
6. Write the Python program that matches the logic in the flowcharts.
For this assignment, the customer’s account balance will be computed and displayed for a bank transaction. Use the main function flowchart provided to code the main function. Design functions to: 1) process a withdrawal; 2) process a deposit; 3) process an invalid transaction code; and 4) display the customer’s balance after the transaction is complete. The customer’s new balance will be the same as their previous balance if an error has occurred. Use a format specifier to print the customer’s balance for dollars and cents including a dollar sign. Create the flowcharts for the 4 functions and the Python program to solve the problem.
The user will input their name, account ID, transaction code (W or w = withdrawal, D or d = deposit), previous balance, and transaction amount. If an invalid code is entered, an error message is displayed and the balance remains unchanged (i.e. new balance = previous balance). If the customer attempts to withdraw more money than is in their account, a different error message is displayed and the balance remains unchanged. Otherwise, the customer’s balance is adjusted accordingly (i.e. add the transaction amount for deposits and subtract it for withdrawals). The customer’s balance is only printed in the display balance function (i.e. not in any of the other functions).
Calculate the new balance for each set of input test data shown below. Use this test data when verifying your structure chart, flowcharts, and program.'
#-------------------------------------------------------------------------------
#Program: Bank Transaction
#Programmer: David Specht
#Date: 2/16/2011
#Abstract: This program computes and displays a customer's bank transaction.
#-------------------------------------------------------------------------------
#Define the main function
def main():
#Display the purpose of this program
print 'This program computes and displays customers account balance for a bank transaction.'
#Input customer name
customer_name = raw_input('Please enter your name:')
#Input customer account ID
account_id = raw_input('Please enter your account ID:')
#Input transaction code
transaction_code = raw_input( 'Please enter W for a withdrawal or D for a deposit:')
#Input previous balance
previous_balance = raw_input('Please enter your previous balance:')
#Input transaction amount
transaction_amount = raw_input('Please enter the transaction amount: ')
#Call process withdrawal code enter
withdrawal_code(transaction_code, process_withdrawal, process_deposit, previous_balance, transaction_amount)
#Call process to display balance
display_balance
process_deposit(previous_balance, transaction_amount)
process_withdrawal(previous_balance, transaction_amount)
#Define the withdrawal_code function
def withdrawal_code(transaction_code, process_withdrawal, process_deposit, previous_balance, transaction_amount):
#Determine if code entered calls for a withdrawal
if transaction_code == 'W' or transaction_code == 'w':
process_withdrawal(previous_balance, transaction_amount)
#Determine if code entered calls for a deposit
elif transaction_code == 'D' or transaction_code == 'd':
process_deposit(previous_balance, transaction_amount)
#Display error message
else:
print 'Sorry, this is not a valid transaction code. Your balance will remain $%.5f:' % previous_balance
def process_withdrawal(previous_balance, transaction_amount):
new_balance = previous_balance - transaction_amount
if transaction_amount > previous_balance:
print 'The amount entered exceeds your current balance'
else:
display_balance
def process_deposit(previous_balance, transaction_amount):
new_balance = previous_balance + transaction_amount
#Define the display_balance function
def display_balance(new_balance):
print 'Your current balance is $%.10f' % new_balance
#Call the main function
main()


Sign In
Create Account

Back to top









