Any programmers???

Discussion in 'Off-Topic' started by MOsubie, Mar 27, 2012.

  1. MOsubie
    Offline

    MOsubie Well-Known Member

    Likes Received:
    15
    Trophy Points:
    203
    Hi,

    I'm having an issue with my python program. I can't get it to stop asking questions so that I can continue with the program.

    LMK asap. I'll send the program via email.

    Thanks
     
  2. SurlyOldManMN
    Offline

    SurlyOldManMN Omdat fok jou Staff Member

    Likes Received:
    1,854
    Trophy Points:
    348
    I don't know python but I can take a gander. Pretty vague problem description. Could be a simple control structure thing.

    Try StackOverflow.com. Serious, serious nerdery 24/7. However, you will have to put A WHOLE ASSTON more effort into how you ask your question than you did here. Fair warning... ;)
     
  3. JasonoJordan
    Offline

    JasonoJordan Well-Known Member

    Likes Received:
    1,723
    Trophy Points:
    398
    OMGZ another person wanting us to do their homework!! o wait do they even still teach python anywhere lolz.
     
  4. SurlyOldManMN
    Offline

    SurlyOldManMN Omdat fok jou Staff Member

    Likes Received:
    1,854
    Trophy Points:
    348
    Yeah... but with programming, if they don't get the hint that you'll only give direction, not answers; you can then spoon feed them a technically correct example written in a way that nobody in their right mind would ever consider. Like initializing a random number generator that will generate a number between .1 and .9, then round up, instead of "true". Mod by 1 for false. Any teacher/professor who sees that 'ish is going to know exactly where it came from. It's good fun.

    I've put more effort into less entertaining activities. :)
     
    pksublime likes this.
  5. prezawagon
    Offline

    prezawagon Well-Known Member

    Likes Received:
    49
    Trophy Points:
    233
    If you haven't already, go search and then ask on Stack Overflow. There are some smart people and python seems to be a popular language there.

    Good luck.
     
  6. MOsubie
    Offline

    MOsubie Well-Known Member

    Likes Received:
    15
    Trophy Points:
    203
    Haha, sorry guys

    Well, here's the issue.

    I'm writing a loop that asks for some information. Then when I want the loop to stop I'm suppose to tell them to enter in "DONE" but my loop just keeps going and going. Been going at this for awhile now.

    Heres my file
     

    Attached Files:

  7. JasonoJordan
    Offline

    JasonoJordan Well-Known Member

    Likes Received:
    1,723
    Trophy Points:
    398
    its been a long time since i read any code. Not sure if this works anything like C++ or not but could you not have a statement that sets a bit to a 1 if you enter Done. Then have a if statement to jump you out of the loop?
     
  8. JasonoJordan
    Offline

    JasonoJordan Well-Known Member

    Likes Received:
    1,723
    Trophy Points:
    398
    Also not sure what you want it to do when done is entered but looking over it i dont see done being defined anywhere.(been up a long time today so could just be over looking it)
     
  9. MOsubie
    Offline

    MOsubie Well-Known Member

    Likes Received:
    15
    Trophy Points:
    203
    Well "done" is suppose to be right under the append. But the text I put up isn't the revised. And now I'm in bed. I'll post it up in a bit or maybe earlier around 6.
     
  10. ryjacobs
    Offline

    ryjacobs Well-Known Member

    Likes Received:
    742
    Trophy Points:
    298
    Doesn't look like you're checking the value of anything to be 'DONE', but it is pretty tough to see the formatting on my iPhoner. Also, I have never used Python before.
     
  11. SurlyOldManMN
    Offline

    SurlyOldManMN Omdat fok jou Staff Member

    Likes Received:
    1,854
    Trophy Points:
    348
    It has been at least 12 hours since I looked at some code... ;)

    Try adding this to line 15, see if it helps clear up what's going on:

    print "Current strPayEmpl value: ",strPayEmpl

    like so:

    http://pastebin.com/g9zEi3nS


    Timing is everything mang. ;)


    also, if you're going to check a condition at the end of your while loop, I would suggest not bothering to check at the beginning of the loop. Something like "while true:" usually works just fine. Again, I'm no Python guy, but if that's possible it will clean up the code and make it more obvious what you're trying to do. You could get rid of the first set of "dummy" values. That's assuming you don't HAVE to initialize them first for some other reason.

    Clear as mud?
     
  12. SurlyOldManMN
    Offline

    SurlyOldManMN Omdat fok jou Staff Member

    Likes Received:
    1,854
    Trophy Points:
    348
    One more thing... "DONE" is not a zero length string. Check your condition itself.
     
  13. MOsubie
    Offline

    MOsubie Well-Known Member

    Likes Received:
    15
    Trophy Points:
    203
    Okay, here is what I also came up with.

    Thanks, but I believe dummy has to be in there. But will double check again.
     

    Attached Files:

  14. pksublime
    Offline

    pksublime Well-Known Member

    Likes Received:
    53
    Trophy Points:
    233
    my advice would be to keep all numeric data as numeric, then only cast/parse it to a string when you need to display and or write it
     
  15. iridium7777
    Offline

    iridium7777 Well-Known Member

    Likes Received:
    39
    Trophy Points:
    113
    I could write this **** in qbasic in 2 mins...
     
  16. SurlyOldManMN
    Offline

    SurlyOldManMN Omdat fok jou Staff Member

    Likes Received:
    1,854
    Trophy Points:
    348
    Do you still have questions?
     
  17. qstarin
    Offline

    qstarin Well-Known Member

    Likes Received:
    22
    Trophy Points:
    223

    Cool story bro.
     
    idget likes this.
  18. prezawagon
    Offline

    prezawagon Well-Known Member

    Likes Received:
    49
    Trophy Points:
    233
    I've never written anything in python, but a few comments.

    Like surly said, "dummy" is not needed. just change your while loop to while True: and remove strPayEmpl entirely.

    Also, what if the employee works 37.5 hours, or makes $12.50. You're parsing those values as int, but I think it's very common to have float values there.

    In general, try to have your functions be responsible for one task. Right now GetPayInfo is displaying a menu (basically this is your entire user interface) and it also contains the logic for calculating the gross pay. Consider creating a function that calculates gross pay and move the logic out of the while loop.

    Avoid "magic numbers", I see the number 40 in the program three times. If the business decides to only pay overtime after 50 hours, you need to update your program in multiple places. It's trivial in this program, but in the real world with a large program you WILL miss one of those places when updating. Create a definition for the number of hours in a workweek, use a descriptive variable name and now you only have one place to update the value if it changes. Similar advice for the value 1.5. It's only used once, but if you create a variable to hold the value then you can give it a meaningful name so it's clear to the person reading your code what that value means.

    Good luck and have fun.
     
  19. qstarin
    Offline

    qstarin Well-Known Member

    Likes Received:
    22
    Trophy Points:
    223
    ^ prezawagon's giving good general advice. One nitpick, use decimal for currency instead of float. StackOverflow is also a very good site to use, as others said.
     
  20. MOsubie
    Offline

    MOsubie Well-Known Member

    Likes Received:
    15
    Trophy Points:
    203
    Nope, got it to run but only after I enter done then it will activate the loop. Have to look into it...

    Thanks guys
     
  21. SurlyOldManMN
    Offline

    SurlyOldManMN Omdat fok jou Staff Member

    Likes Received:
    1,854
    Trophy Points:
    348
    I doubt that. You're prompting from inside the loop. How do you get to a point where you can "enter done"?

    Put some more print statements in there to inspect your variables at run time and tell you what's going on.
     
  22. prezawagon
    Offline

    prezawagon Well-Known Member

    Likes Received:
    49
    Trophy Points:
    233
    You're calling your loop twice, you have lstPayInfo = GetPayInfo() in your program twice. Every time you call GetPayInfo you'll have to enter 'done' to get out of the loop, that's probably what you're seeing.

    Find out if you really need to call it a second time. If you do, why? Can you write a separate function that can be called from both GetPayInfo and the mainline code?