Some python newb help please?
So I'm trying to write a program for a problem in class, and something strange is happening that I can't figure out why is happening. I was wondering if you guys could help me fix it? http://pastebin.com/6QZTvx6Z Basically, 1 and 2 work just fine as inputs, but whenever I input 3 or 4, idle just doesn't do anything. Does anyone know why that is? any suggestions on how to fix? Any help is much appreciated :) -- https://mail.python.org/mailman/listinfo/python-list
Re: Some python newb help please?
On 12/11/2013 22:14, lrwarre...@gmail.com wrote: So I'm trying to write a program for a problem in class, and something strange is happening that I can't figure out why is happening. I was wondering if you guys could help me fix it? http://pastebin.com/6QZTvx6Z Basically, 1 and 2 work just fine as inputs, but whenever I input 3 or 4, idle just doesn't do anything. Does anyone know why that is? any suggestions on how to fix? Any help is much appreciated :) Please put your code inline so we can see it, if it's too long see this http://sscce.org/ for advice. -- Python is the second best programming language in the world. But the best has yet to be invented. Christian Tismer Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list
Re: Some python newb help please?
On Tuesday, November 12, 2013 4:21:58 PM UTC-6, Mark Lawrence wrote: On 12/11/2013 22:14, lr@gmail.com wrote: So I'm trying to write a program for a problem in class, and something strange is happening that I can't figure out why is happening. I was wondering if you guys could help me fix it? http://pastebin.com/6QZTvx6Z Basically, 1 and 2 work just fine as inputs, but whenever I input 3 or 4, idle just doesn't do anything. Does anyone know why that is? any suggestions on how to fix? Any help is much appreciated :) Please put your code inline so we can see it, if it's too long see this http://sscce.org/ for advice. -- Python is the second best programming language in the world. But the best has yet to be invented. Christian Tismer Mark Lawrence I'm not quite sure what you mean by that. it was on that pastebin link. I'll post it again here though. it's no longer than half a page. x = 0 y = 0 quitCommand = 0 print Welcome to the World of Textcraft! print -- print while quitCommand != int(5): print You are currently at ( + str(x) + , + str(y) + ) print Enter a command (1 = North, 2 = East, 3 = South, 4 = West, 5 = Exit): if int(raw_input()) == 1: print Moving north y = y + 1 elif int(raw_input()) == 2: print Moving east x = x + 1 elif int(raw_input()) == 3: print Moving south y = y - 1 elif int(raw_input()) == 4: print Moving west x = x - 1 elif int(raw_input()) == 5: print Dost thou leave so soon? Fare thee well! quitCommand = 5 else: print I find your lack of reading comprehension skills disturbing. -- https://mail.python.org/mailman/listinfo/python-list
Re: Some python newb help please?
Welcome to the world of Python programming! I'm glad you're learning this great language. As to your bug, think about this: in each if or elif statement, you're reading the user input again, so if user input is NOT equal to 1 in the first place, it reads input again. Try to step through your code mentally, or even on paper, and track *exactly* what's happening. You could also add some print statements to see where you are. Good luck with your coding. Consider reading user input only once, and then checking it against the values 1,2,3,4, and 5. As an aside, int(5) is from the department of redundancy department. ;-) --John Strickler On Tuesday, November 12, 2013 5:14:42 PM UTC-5, lrwar...@gmail.com wrote: So I'm trying to write a program for a problem in class, and something strange is happening that I can't figure out why is happening. I was wondering if you guys could help me fix it? http://pastebin.com/6QZTvx6Z Basically, 1 and 2 work just fine as inputs, but whenever I input 3 or 4, idle just doesn't do anything. Does anyone know why that is? any suggestions on how to fix? Any help is much appreciated :) -- https://mail.python.org/mailman/listinfo/python-list
Re: Some python newb help please?
First thing would you please read and action this https://wiki.python.org/moin/GoogleGroupsPython so we don't have to read double spaced google crap, thanks. On 12/11/2013 22:27, lrwarre...@gmail.com wrote: On Tuesday, November 12, 2013 4:21:58 PM UTC-6, Mark Lawrence wrote: On 12/11/2013 22:14, lr@gmail.com wrote: So I'm trying to write a program for a problem in class, and something strange is happening that I can't figure out why is happening. I was wondering if you guys could help me fix it? http://pastebin.com/6QZTvx6Z Basically, 1 and 2 work just fine as inputs, but whenever I input 3 or 4, idle just doesn't do anything. Does anyone know why that is? any suggestions on how to fix? Any help is much appreciated :) Please put your code inline so we can see it, if it's too long see this http://sscce.org/ for advice. -- Python is the second best programming language in the world. But the best has yet to be invented. Christian Tismer Mark Lawrence I'm not quite sure what you mean by that. it was on that pastebin link. I'll post it again here though. it's no longer than half a page. x = 0 y = 0 quitCommand = 0 print Welcome to the World of Textcraft! print -- print You don't need the double quotes in the line above, the print statement on its own will output a newline. while quitCommand != int(5): print You are currently at ( + str(x) + , + str(y) + ) print Enter a command (1 = North, 2 = East, 3 = South, 4 = West, 5 = Exit): if int(raw_input()) == 1: print Moving north y = y + 1 elif int(raw_input()) == 2: print Moving east x = x + 1 elif int(raw_input()) == 3: print Moving south y = y - 1 elif int(raw_input()) == 4: print Moving west x = x - 1 elif int(raw_input()) == 5: print Dost thou leave so soon? Fare thee well! quitCommand = 5 else: print I find your lack of reading comprehension skills disturbing. You're asking for input in every comparison. Change this to request the input once, store it and then compare it. If you rename quitCommand to command, you'd have command = int(raw_input()) if command == 1: etc. Enjoy :) -- Python is the second best programming language in the world. But the best has yet to be invented. Christian Tismer Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list
Re: Some python newb help please?
On 2013-11-12 14:27, lrwarre...@gmail.com wrote: if int(raw_input()) == 1: print Moving north y = y + 1 elif int(raw_input()) == 2: print Moving east x = x + 1 elif int(raw_input()) == 3: print Moving south y = y - 1 elif int(raw_input()) == 4: print Moving west x = x - 1 elif int(raw_input()) == 5: print Dost thou leave so soon? Fare thee well! quitCommand = 5 else: print I find your lack of reading comprehension skills disturbing. Note that you're asking for input with each comparison. Best to get the input once and store it in a variable before the if statement and then do the comparisons against the same value. -tkc -- https://mail.python.org/mailman/listinfo/python-list
Re: Some python newb help please?
On 12/11/2013 22:27, lrwarre...@gmail.com wrote: On Tuesday, November 12, 2013 4:21:58 PM UTC-6, Mark Lawrence wrote: On 12/11/2013 22:14, lr@gmail.com wrote: So I'm trying to write a program for a problem in class, and something strange is happening that I can't figure out why is happening. I was wondering if you guys could help me fix it? [snip] x = 0 y = 0 quitCommand = 0 print Welcome to the World of Textcraft! print -- print You can simplify that to: print while quitCommand != int(5): 5 is already an int, so int(5) == 5. print You are currently at ( + str(x) + , + str(y) + ) print Enter a command (1 = North, 2 = East, 3 = South, 4 = West, 5 = Exit): if int(raw_input()) == 1: You're asking the user to enter something and then checking whether its int value is 1. print Moving north y = y + 1 elif int(raw_input()) == 2: Now you're asking the user to enter something _again_ and then checking whether its int value is 2. In other words, in order for it to print Moving east the following steps must occur: 1. Ask the user to enter something. 2. Check whether it's 1. It isn't. (Previous condition) 3. Ask the user to enter something. 4. Check whether it's 2. (This condition) print Moving east x = x + 1 elif int(raw_input()) == 3: Similar remarks to above, but longer. print Moving south y = y - 1 elif int(raw_input()) == 4: Similar remarks to above, but longer again. print Moving west x = x - 1 elif int(raw_input()) == 5: Similar remarks to above, but longer again. print Dost thou leave so soon? Fare thee well! quitCommand = 5 else: print I find your lack of reading comprehension skills disturbing. The fix is simple. Ask once: answer = int(raw_input()) if answer == 1: ... elif answer == 2: ... ... -- https://mail.python.org/mailman/listinfo/python-list
Re: Some python newb help please?
On Wed, Nov 13, 2013 at 9:27 AM, lrwarre...@gmail.com wrote: I'm not quite sure what you mean by that. it was on that pastebin link. I'll post it again here though. it's no longer than half a page. Inline means what you did in this post. Out-of-line means providing us with a link to where the code is. This forum isn't just a Google Groups web-based discussion group; it's primarily a newsgroup (comp.lang.python) and an email address (python-list@python.org). Both of those can be read by people who don't have internet access, so putting your code in an http link might prevent them from reading it. Also, the group/list gets archived all over the place, and there's no guarantee that pastebin will still be around a hundred years from now. It's an unnecessary dependency, which inline code doesn't have. That's why posting right here is the safe option :) Two general comments. Firstly, you're using Python 2 here. Is there a reason for that? If you possibly can, switch to Python 3. All sorts of things have been improved, and the gap is only going to widen - there won't be a Python 2.8, and subsequent 2.7.x releases are bugfixes and security patches only. All the new shinies are in 3.x. And secondly, please PLEASE avoid Google Groups; your quoted text is ugly and annoying, and your own text isn't wrapped. Check this out, and preferably, find an alternative means of posting: https://wiki.python.org/moin/GoogleGroupsPython ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Some python newb help please?
On Tuesday, November 12, 2013 4:56:35 PM UTC-6, MRAB wrote: On 12/11/2013 22:27, l...@gmail.com wrote: On Tuesday, November 12, 2013 4:21:58 PM UTC-6, Mark Lawrence wrote: On 12/11/2013 22:14, lr@gmail.com wrote: So I'm trying to write a program for a problem in class, and something strange is happening that I can't figure out why is happening. I was wondering if you guys could help me fix it? [snip] x = 0 y = 0 quitCommand = 0 print Welcome to the World of Textcraft! print -- print You can simplify that to: print while quitCommand != int(5): 5 is already an int, so int(5) == 5. print You are currently at ( + str(x) + , + str(y) + ) print Enter a command (1 = North, 2 = East, 3 = South, 4 = West, 5 = Exit): if int(raw_input()) == 1: You're asking the user to enter something and then checking whether its int value is 1. print Moving north y = y + 1 elif int(raw_input()) == 2: Now you're asking the user to enter something _again_ and then checking whether its int value is 2. In other words, in order for it to print Moving east the following steps must occur: 1. Ask the user to enter something. 2. Check whether it's 1. It isn't. (Previous condition) 3. Ask the user to enter something. 4. Check whether it's 2. (This condition) print Moving east x = x + 1 elif int(raw_input()) == 3: Similar remarks to above, but longer. print Moving south y = y - 1 elif int(raw_input()) == 4: Similar remarks to above, but longer again. print Moving west x = x - 1 elif int(raw_input()) == 5: Similar remarks to above, but longer again. print Dost thou leave so soon? Fare thee well! quitCommand = 5 else: print I find your lack of reading comprehension skills disturbing. The fix is simple. Ask once: answer = int(raw_input()) if answer == 1: ... elif answer == 2: ... ... Thanks a lot! I'll try this out! Sorry to everyone else whose eyes I made bleed. I've never used a newsgroup before...still not really sure what they are. Found this through a google search :\ -- https://mail.python.org/mailman/listinfo/python-list
Re: Some python newb help please?
On Tue, 12 Nov 2013 14:14:42 -0800, lrwarren94 wrote: http://pastebin.com/6QZTvx6Z Work through your code very very carefully. You're doing something in each if branch that you probably only want to do once in each execution of the while loop. If you can't figure it out, I'll post a corrected version next week. -- Denis McMahon, denismfmcma...@gmail.com -- https://mail.python.org/mailman/listinfo/python-list
Re: Some python newb help please?
On Wed, Nov 13, 2013 at 10:04 AM, lrwarre...@gmail.com wrote: Thanks a lot! I'll try this out! Sorry to everyone else whose eyes I made bleed. I've never used a newsgroup before...still not really sure what they are. Found this through a google search :\ There's an easy fix. Go to this page: https://mail.python.org/mailman/listinfo/python-list You can then subscribe to the mailing list using whatever email address you're comfortable with. I use Gmail, which works fairly well but has its own issues; I've glanced at Evolution (a Linux mail client) and its way of handling threads, and it seems to do a good job. Plenty of options. ChrisA -- https://mail.python.org/mailman/listinfo/python-list