Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7548169
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:37:52+00:00 2026-05-30T09:37:52+00:00

First, I will warn you, I am new at this so please bear with

  • 0

First, I will warn you, I am new at this so please bear with me. I created the following program (for a class, of course) and everything works except that the withdrawal calculation spits out a negative number when the value shouldn’t be negative. Can you guys see what I’m doing wrong?

Thanks in advance

#define the main
def main():
    name=input('Enter the customer\'s name: ')
    account_id=input('Enter the account ID: ')
    code=input('Enter the transaction code:')
    previous_balance=float(input('Enter the previous balance: '))
    transaction_amount=float(input('Enter the transaction amount: '))

    if code == "w" or code == "W":
        process_withdrawal (transaction_amount, previous_balance)
    else:
        if code == "d" or code == "D":
            process_deposit (transaction_amount, previous_balance)
        else:
            process_invalid_transaction_code (previous_balance)

#define process withdrawal
def process_withdrawal (previous_balance, transaction_amount):
    if previous_balance >= transaction_amount:
        print('You have entered an invalid transaction amount')
        balance=previous_balance
        print_balance (balance)                

    else:
        balance=previous_balance-transaction_amount
        print_balance (balance)        

#define process deposit
def process_deposit (previous_balance, transaction_amount):
    balance=previous_balance+transaction_amount
    print_balance (balance)

#define invalid transaction code
def process_invalid_transaction_code (previous_balance):
    print('You have entered an invalid transaction code.')
    balance=previous_balance
    print_balance (balance)

#define print balance
def print_balance(balance):
    print('Your current balance is :', format(balance, '.2f'))

main()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T09:37:53+00:00Added an answer on May 30, 2026 at 9:37 am

    Your call to process_withdrawal has the first argument as transaction_amount and the second as previous_balance, but the function declaration has previous_balance as the first argument and transaction_amount as the second.

    Try this:

    if code == "w" or code == "W":
      process_withdrawal(previous_balance, transaction_amount)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know one awkward solution for this taks will be : first use ct
By default, EF code first will create a database in C:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\DATA
First I will try to explain what I want to do. The app loads
I have a CSV file. The first row will always contain column headers. Depending
I have two desktop applications. After closing the first application, the first application will
I want to display a UITableView with Multiple Columns. The first column will have
Which command will executed first,If a stored procedure have individual multiple select commands;
I am writing my first project that will use autoconf and teaching it to
For example, will the first piece of code perform a full search twice, or
With :limit in query, I will get first N records. What is the easiest

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.