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 7696009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:40:50+00:00 2026-05-31T21:40:50+00:00

I am working on this homework assignment and I am stuck on what I

  • 0

I am working on this homework assignment and I am stuck on what I know to be a very simple problem. The premise of the code is a petty cash system in which the user can make deposits, withdraws, and get their current balance.
My problem is that the withdraws and deposits don’t seem to be going through my Account class. Is it a global variable issue? I’ll be adding timestamps later. Thank you in advance.

import datetime
import time

class Account:
    def __init__(self, initial):
        self.balance = initial

    def deposit(self, amt):
        self.balance = self.balance + amt

    def withdraw(self,amt):
        self.balance = self.balance - amt

    def getbalance(self):
        return self.balance

def yesno(prompt): 
    ans = raw_input(prompt) 
    return (ans[0]=='y' or ans[0]=='Y')

def run():  
    done = 0   
    while not done: 
        user_options()
        print
        done = not yesno("Do another? ")
        print

def user_options():
    print ("Here are your options:")
    print
    print ("   (a) Deposit cash")
    print ("   (b) Withdraw cash")
    print ("   (c) Print Balance")
    print
    u = raw_input("Please select a letter option: ").lower()
    user_input(u)

def user_input(choice):
    account = Account(0.00)
    if choice == "a" or choice == "b" or choice == "c":

        if choice == "a":
            d = input("Enter Deposit Amount: $")
            account.deposit(d)

        if choice == "b":
            w = input ("Enter Withdraw Amount: $")
            account.withdraw(w)

        if choice == "c":
            print ("Balance Amount: $"),
            print account.getbalance()

    else:
        print ("Not a correct option")


run()

#now = datetime.datetime.now()

Python Version: 2.7.2

  • 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-31T21:40:51+00:00Added an answer on May 31, 2026 at 9:40 pm

    The problem is:

    account = Account(0.00)
    

    Every time user_input is called, you create a new, empty account. Since user_input is called from user_options which is called inside the while loop in run, this happens before every transaction.

    You need to move that line out of the loop, for example:

    def run():
        done = 0
        global account # just showing you one way, not recommending this
        account = Account(0.00)
        while not done:
            user_options()
            print
            done = not yesno("Do another? ")
            print
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Working on a homework assignment and am stuck with this task: Create a loop
I am currently working on a homework assignment and I am thoroughly stuck. I
I'll preface this by saying it's a homework assignment. I don't want code written
I am doing a little homework assignment in which we are making a very
I have a problem with my homework assignment and I do not know where
I am working on my last homework assignment for COBOL this semester and I
I am working with cal for a homework assignment and i am stuck on
I am working on my homework assignment and I am completely stuck! What I
I'm working on this homework that's kind of confusing me... I am provided with
This is a homework I am working towards to familiar myself with TDD and

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.