+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 16

Thread: Beginners [Read This]

  1. #1
    Join Date
    Oct 2008
    Location
    Pahrump, Nevada
    Posts
    787
    Blog Entries
    1
    Rep Power
    20

    Post Beginners [Read This]

    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.

    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.

    +Friend Me | My Graphics | Forum Rules | Help Forum | Forum FAQ

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Location
    Advertising world
    Posts
    Many

     
  3. #2
    Join Date
    Sep 2008
    Location
    Australia
    Posts
    4,834
    Blog Entries
    10
    Rep Power
    51

    Re: Beginners [Read This]

    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!

  4. #3
    Join Date
    Oct 2008
    Location
    Pahrump, Nevada
    Posts
    787
    Blog Entries
    1
    Rep Power
    20

    Re: Beginners [Read This]

    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.

    +Friend Me | My Graphics | Forum Rules | Help Forum | Forum FAQ

  5. #4
    Join Date
    Sep 2008
    Location
    Australia
    Posts
    4,834
    Blog Entries
    10
    Rep Power
    51

    Re: Beginners [Read This]

    I understand what got you confused Welcome to CC mate.

    Well it is really good for your very first project Yer, 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!

  6. #5
    Join Date
    Oct 2008
    Location
    Pahrump, Nevada
    Posts
    787
    Blog Entries
    1
    Rep Power
    20

    Post Re: Beginners [Read This]

    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.

    +Friend Me | My Graphics | Forum Rules | Help Forum | Forum FAQ

  7. #6
    TkTech's Avatar
    TkTech is offline The Crazy One
    Join Date
    Jun 2006
    Location
    Canada
    Posts
    1,412
    Blog Entries
    1
    Rep Power
    31

    Re: Beginners [Read This]

    Post moved. Thanks for the submission!

  8. #7
    Join Date
    Sep 2008
    Location
    Australia
    Posts
    4,834
    Blog Entries
    10
    Rep Power
    51

    Re: Beginners [Read This]

    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!

  9. #8
    Join Date
    Oct 2008
    Location
    Pahrump, Nevada
    Posts
    787
    Blog Entries
    1
    Rep Power
    20

    Re: Beginners [Read This]

    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.

    +Friend Me | My Graphics | Forum Rules | Help Forum | Forum FAQ

  10. #9
    Join Date
    Sep 2008
    Location
    Australia
    Posts
    4,834
    Blog Entries
    10
    Rep Power
    51

    Re: Beginners [Read This]

    Nice work Donovan Maybe show some possible errors in this script?

  11. #10
    Join Date
    Oct 2008
    Location
    Pahrump, Nevada
    Posts
    787
    Blog Entries
    1
    Rep Power
    20

    Re: Beginners [Read This]

    I am going to have this post deleted. Then I will write a new guide. I am actually going to write one today

    +Friend Me | My Graphics | Forum Rules | Help Forum | Forum FAQ

+ Reply to Thread
Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Any Python beginners ?
    By ToX in forum Python
    Replies: 54
    Last Post: 10-11-2010, 06:09 AM
  2. C programs for beginners
    By Dofoar in forum C and C++
    Replies: 16
    Last Post: 08-12-2010, 08:46 AM
  3. A tiny bit of beginners help
    By TheLea in forum C# Programming
    Replies: 3
    Last Post: 03-09-2010, 05:41 AM
  4. Beginners question
    By goatmafioso in forum C and C++
    Replies: 5
    Last Post: 02-09-2010, 07:08 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts