First off before I begin, If you are a moderator and can see I suck at typing -.- and want to modify my mistakes. Please do soIf you think you can reword a sentence to make it better understandable again please do so. If you do not understand something please PM me and I will try to explain it better
or add Donovan.Simon@hotmail.com and I can talk to you live on MSN.
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.
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 tablesCode: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
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 aaronI 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.
I believe this is a tutorial. Nice work anyways, it will be moved soon![]()
jQuery Selectors Tutorial - jQuery Striped Table tutorial - jQuery Events - jQuery Validation
Sorry if I don't post as often as I did, I'll try to get here as much as possible! I'm working my bum off to get this scholarship and other stuff!
Ahh, lol I thought if it was Python related I should just put it hereI just joined the site today. This was my very first project I coded in python so I released it. I knew it had a good example of some mistakes people make
Kinda like I did.
I understand what got you confusedWelcome to CC mate.
Well it is really good for your very first projectYer, but it is just a little echo/print error. Not really error just incorrect output
![]()
jQuery Selectors Tutorial - jQuery Striped Table tutorial - jQuery Events - jQuery Validation
Sorry if I don't post as often as I did, I'll try to get here as much as possible! I'm working my bum off to get this scholarship and other stuff!
Well it always helps to knowBelieve it or not took some mind thinking to figure out why it was not working at first. But that is good for a beginning programmer. We need to learn how to debug as well as we can write code.
Post moved. Thanks for the submission!
That is completely true mate. It's always best to make mistakes and correct them, at least then you get use to the errors and know how to fix them
I sometimes make mistake purporsly.
jQuery Selectors Tutorial - jQuery Striped Table tutorial - jQuery Events - jQuery Validation
Sorry if I don't post as often as I did, I'll try to get here as much as possible! I'm working my bum off to get this scholarship and other stuff!
To the beginners who read this. This code I put above will work, but it is improper code. The correct way to write that program would be.
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 Balance -= Withdraw Withdraw = input ("Withdraw: ") print "Your current balance is now", Balance - Withdraw print "Thank you for playing The Stupid Balance Game your final balance is:", Balance - Withdraw
Using the -= to recall the Balance and subtract the users input of Withdraw.
Nice work DonovanMaybe show some possible errors in this script?
I am going to have this post deleted. Then I will write a new guide. I am actually going to write one today![]()
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks