I find that it is sometimes complicated to work out numbers and code with python if things are going off of the same name.
For example. Aaron.H and I developed a small bank system type code.
print "How much is your starting balance?"
Balance = input ("Balance: ")
print "How much would you like to withdraw from your current Balance of", Balance
Withdraw = input ("Withdraw: ")
print "Your current balance is now", Balance - Withdraw
print "How much would you like to withdraw from your current Balance of"
print Balance - Withdraw
Withdraw2 = input ("Withdraw: ")
print "Your current balance is now", Balance - Withdraw - Withdraw2
print "Thank you for playing The Stupid Balance Game your final balance is:", Balance - Withdraw - Withdraw2
The problem was we where trying to use withdraw twice and it would always give us an already existing value. Or it would simply just fail. So to work around getting errors when making a calculating function. Make sure you rename your tables:)
i.e: If you are trying to write a bank system like Aaron and I did. Then you would have to do this. I will break it down and explain each part.
print "How much is your starting balance?"
Balance = input ("Balance: ")
The code "Balance = input ("balance: ")" means that the number they type and press enter with is now the "Balance". So if they Press enter with the number 1000 for instance. Then everywhere you put ,balance it will say 1000. This means you can not always assume when you say withdraw. That the balance is always ,balance. Because it will then appear as 1000 and not subtract what the put in.
print "How much would you like to withdraw from your current Balance of", Balance
Withdraw = input ("Withdraw: ")
Alright, so this asks how much the person wants to withdraw from there current balance. of 1000. So if the person types 500 then you put the next line of code as. "print "Your current balance is now", Balance" again it will say the final balance is 1000. Which would be wrong. So instead you just use Balance - Withdraw. The same as The number they entered as there balance subtract how much they withdrew.
print "Your current balance is now", Balance - Withdraw
Now this is again something I overlooked when making this with aaron:) I was thinking I just had to put ,balance and it would correct it for me lol but you have to make sure it says Balance - Withdraw.
print "How much would you like to withdraw from your current Balance of", Balance - Withdraw
Well now you are stuck, You can't figure out that while you put withdraw again and run the simulation of the bank. That the number never add up quite right. This is because you are asking it to withdraw from balance. Meaning it is now doing the exact same thing it was doing when you stared. So in order to keep this thing going with correct values. You must rename the second withdraw. Just renaming the table and keeping ("Withdraw: ") the same so it will still appear to say Withdraw for the user.
Withdraw2 = input ("Withdraw: ")
So all you have to do is rename this and you are good on that part:)
Now you can't just say Your balance is now Balance - Withdraw2 because again it would skip the first withdraw statement and the numbers again would end up wrong. In order to fix they you have to put Balance - Withdraw - Withdraw2 for the final ending number.
print "Your current balance is now", Balance - Withdraw - Withdraw2
print "Thank you for playing The Stupid Balance Game your final balance is:", Balance - Withdraw - Withdraw2
So now you have completed all that. There final balance should be Balance - Withdraw - Withdraw2 substituting what you have named your tables. This should all work fine. If you read this you will have a better understanding with python. The reason aaron and I teamed up is because we are both 14 and are inspired coders. So we decided to make our first project which is this bank. We got stumped at some codes and figured it out by debugging. This was a very good code to make because we had to both think out side of the box and think of the obvious.
I hope this helped. Do not only thank me even though I wrote the guide aaron still helped me right the code. We both wrote pieces of the code and got it to work.


Sign In
Create Account



Back to top









