Jump to content

Beginners [Read This]

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
15 replies to this topic

#1
Donovan

Donovan

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 798 posts
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 so:) If 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.

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.
Posted Image
+Friend Me | My Graphics | Forum Rules | Help Forum | Forum FAQ

#2
Brandon W

Brandon W

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 4,828 posts
I believe this is a tutorial. Nice work anyways, it will be moved soon :D
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!


#3
Donovan

Donovan

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 798 posts
Ahh, lol I thought if it was Python related I should just put it here:) I 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.
Posted Image
+Friend Me | My Graphics | Forum Rules | Help Forum | Forum FAQ

#4
Brandon W

Brandon W

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 4,828 posts
I understand what got you confused :D Welcome to CC mate.

Well it is really good for your very first project :D Yer, but it is just a little echo/print error. Not really error just incorrect output :D
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!


#5
Donovan

Donovan

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 798 posts
Well it always helps to know:) Believe 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.
Posted Image
+Friend Me | My Graphics | Forum Rules | Help Forum | Forum FAQ

#6
TkTech

TkTech

    The Crazy One

  • Moderators
  • 1,396 posts
Post moved. Thanks for the submission!

#7
Brandon W

Brandon W

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 4,828 posts
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 :D

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!


#8
Donovan

Donovan

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 798 posts
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.

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.
Posted Image
+Friend Me | My Graphics | Forum Rules | Help Forum | Forum FAQ

#9
Brandon W

Brandon W

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 4,828 posts
Nice work Donovan :D Maybe show some possible errors in this script?

#10
Donovan

Donovan

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 798 posts
I am going to have this post deleted. Then I will write a new guide. I am actually going to write one today:)
Posted Image
+Friend Me | My Graphics | Forum Rules | Help Forum | Forum FAQ

#11
Brandon W

Brandon W

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 4,828 posts
hehe Don't get posts deleted :D Others will find it useful, just make a V2 or something.
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!


#12
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
Nice to see you have calmed down with the font sizes, Donovan! +rep

Oh deah - 3 +reps from me == beyond GuRu status. :eek:
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums