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

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):")

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 <module>
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']

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.

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 <module>
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']

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.

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

This question has already been answered. Start a new discussion instead.