954,541 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Very Frustrated

Hi everyone,
I am working on a checkbook balancer for school and my code looks like this:

def process(balance):
trans_type= raw_input("Enter Deposit(d), withdrawal(w), print(p), or quit(q):")
amount=input("Enter the amount:")
if amount<0:
print"You've entered an invalid number."
if trans_type=="d":
balance=int(balance)+int(amount)
print"Your current balance is", balance
elif trans_type=="w":
balance=int(balance)-int(amount)
print"Your current balance is", balance
return balance



def main():
balance=5000
restart=raw_input("Would you like to complete a transaction? (y/n):")
while "y"==restart:
balance = process(balance)



main()

However, when I run the program, i doesn't like some of the numbers I put in for seperate transactions. I get this error message: TypeError: int() argument must be a string or a number, not 'NoneType'. Does anyone know how to fix this? Its due tonight at midnight. PLZ help

Thanks in advance,
Cam

cmharris90
Newbie Poster
4 posts since Nov 2008
Reputation Points: 10
Solved Threads: 0
 

Can you please give us examples of numbers which stuff up the program and the FULL error statement because that will help even more. Also tell us wether you are doing a withdrawal, deposit or something else at that time.

Oh and please wrap your code in code tags. I will do it for you this time

def process(balance):
    trans_type= raw_input("Enter Deposit(d), withdrawal(w), print(p), or quit(q):")
    amount=input("Enter the amount:")
    if amount<0:
        print"You've entered an invalid number."
    if trans_type=="d":
        balance=int(balance)+int(amount)
        print"Your current balance is", balance
    elif trans_type=="w":
        balance=int(balance)-int(amount)
        print"Your current balance is", balance
    return balance



def main():
    balance=5000
    restart=raw_input("Would you like to complete a transaction? (y/n):")
    while "y"==restart:
        balance = process(balance)



main()

Also notice at the while "y" == restart bit? That will never stop executing. Replace all of main with another main method like this:

def main()
    restart = raw_input("Would you like to complete a transaction? (y/n):")
    balance = 5000
    while restart == "y":
        balance = process(balance)
        restart = raw_input("Would you like to complete another transaction? (y/n):")
Paul Thompson
Veteran Poster
1,119 posts since May 2008
Reputation Points: 264
Solved Threads: 183
 

I ran my program, deposited 500, it returned my current balance. I then withdrew 40 and it gave me this error:[Traceback (most recent call last):
File "C:\Documents and Settings\Cameron\My Documents\Cam School\CS 1030\checkbookbalance.py", line 28, in
main()
File "C:\Documents and Settings\Cameron\My Documents\Cam School\CS 1030\checkbookbalance.py", line 24, in main
balance = process(balance)
File "C:\Documents and Settings\Cameron\My Documents\Cam School\CS 1030\checkbookbalance.py", line 14, in process
balance=int(balance)-int(amount)
TypeError: int() argument must be a string or a number, not 'NoneType']

cmharris90
Newbie Poster
4 posts since Nov 2008
Reputation Points: 10
Solved Threads: 0
 

Well this is working for me:

def process(balance):
    trans_type= raw_input("Enter Deposit(d), withdrawal(w), print(p), or quit(q):")
    amount=input("Enter the amount:")
    if amount<0:
        print"You've entered an invalid number."
    if trans_type=="d":
        balance= balance+amount
        print"Your current balance is", balance
    elif trans_type=="w":
        balance= balance-amount
        print"Your current balance is", balance
    return balance



def main():
    balance=5000
    restart=raw_input("Would you like to complete a transaction? (y/n):")
    while "y"==restart:
        balance = process(balance)



main()

I am doing all the things that you say you cant. I took out the changing it to an int with the int() function because it was doing nothing. Perhaps that did something. Try copy-paste my code.. see if it works on your computer.

Paul Thompson
Veteran Poster
1,119 posts since May 2008
Reputation Points: 264
Solved Threads: 183
 

I repeated process with your code and here's what I get: [Traceback (most recent call last):
File "C:\Documents and Settings\Cameron\My Documents\Cam School\CS 1030\checkbookbalance.py", line 28, in
main()
File "C:\Documents and Settings\Cameron\My Documents\Cam School\CS 1030\checkbookbalance.py", line 24, in main
balance = process(balance)
File "C:\Documents and Settings\Cameron\My Documents\Cam School\CS 1030\checkbookbalance.py", line 14, in process
balance= balance-amount
TypeError: unsupported operand type(s) for -: 'NoneType' and 'int']

cmharris90
Newbie Poster
4 posts since Nov 2008
Reputation Points: 10
Solved Threads: 0
 

That means somewhere in your code. Perhaps in a bit that i cant see. There is a bit that makes balance not an int any more. So try and look for places where balance is changed.

Paul Thompson
Veteran Poster
1,119 posts since May 2008
Reputation Points: 264
Solved Threads: 183
 

Thank you for your help. Somehow it worked for me. I kinda fell bass ackwards into the right code. The same way I solve puzzles in portal... accidentally

cmharris90
Newbie Poster
4 posts since Nov 2008
Reputation Points: 10
Solved Threads: 0
 

Okay. Im glad it works. Well done on fixing it yourself.

Paul Thompson
Veteran Poster
1,119 posts since May 2008
Reputation Points: 264
Solved Threads: 183
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You