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
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...
OMGZ another person wanting us to do their homework!! o wait do they even still teach python anywhere lolz.
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.
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.
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
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?
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)
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.
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.
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?
Okay, here is what I also came up with. Thanks, but I believe dummy has to be in there. But will double check again.
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
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.
^ 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.
Nope, got it to run but only after I enter done then it will activate the loop. Have to look into it... Thanks guys
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.
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?