Re: [Tutor] Paper Rock Scissors game - User's choice not returned properly

2011-11-03 Thread Alan Gauld
On 04/11/11 01:42, Steven D'Aprano wrote: Alan Gauld wrote: If you're worried about the screen space and/or keystrokes, you can do this: if direction.upper() in tuple('NSEW'): ... It's not so much the keystrokes that I don't like but it's the fact that I invariably miss out a quote or a co

Re: [Tutor] Paper Rock Scissors game - User's choice not returned properly

2011-11-03 Thread Steven D'Aprano
Alan Gauld wrote: Use the list form, even though it does involve a few more keystrokes and a lot more screen space. The extra typing to avoid the problems are not worth it! :-) If you're worried about the screen space and/or keystrokes, you can do this: if direction.upper() in tuple('NSEW'):

Re: [Tutor] Paper Rock Scissors game - User's choice not returned properly

2011-11-01 Thread Alan Gauld
On 01/11/11 09:46, Peter Otten wrote: Alan Gauld wrote: Good point, although you could test the first character only... if choice[0].lower() not in ('prs'): # NB use a single string What Steven says, plus you may run into an IndexError if choice is the empty string. If you absolutely want

Re: [Tutor] Paper Rock Scissors game - User's choice not returned properly

2011-11-01 Thread Peter Otten
Alan Gauld wrote: > On 31/10/11 20:22, Peter Otten wrote: >> Alan Gauld wrote: >> >>> if choice.lower() not in ('prs'): # NB use a single string >> >> That's not a good idea. If a user accidentally enters PR (for example) >> your version will mistake that for a valid choice. > > Good point, altho

Re: [Tutor] Paper Rock Scissors game - User's choice not returned properly

2011-10-31 Thread Joel Montes de Oca
On 10/31/2011 07:10 PM, Steven D'Aprano wrote: Alan Gauld wrote: On 31/10/11 20:22, Peter Otten wrote: Alan Gauld wrote: if choice.lower() not in ('prs'): # NB use a single string That's not a good idea. If a user accidentally enters PR (for example) your version will mistake that for a v

Re: [Tutor] Paper Rock Scissors game - User's choice not returned properly

2011-10-31 Thread Steven D'Aprano
Joel Montes de Oca wrote: When the user enters an invalid letter, FUNCTION B calls FUNCTION A. FUNCTION A returns choice to FUNCTION B. FUNCTION B does nothing with the return, FUNCTION MAIN gets nothing to returned to it, thus choice is NONE. FUN MAIN | | |__ FUN A |

Re: [Tutor] Paper Rock Scissors game - User's choice not returned properly

2011-10-31 Thread Steven D'Aprano
Alan Gauld wrote: On 31/10/11 20:22, Peter Otten wrote: Alan Gauld wrote: if choice.lower() not in ('prs'): # NB use a single string That's not a good idea. If a user accidentally enters PR (for example) your version will mistake that for a valid choice. Good point, although you could t

Re: [Tutor] Paper Rock Scissors game - User's choice not returned properly

2011-10-31 Thread Alan Gauld
On 31/10/11 20:22, Peter Otten wrote: Alan Gauld wrote: if choice.lower() not in ('prs'): # NB use a single string That's not a good idea. If a user accidentally enters PR (for example) your version will mistake that for a valid choice. Good point, although you could test the first charact

Re: [Tutor] Paper Rock Scissors game - User's choice not returned properly

2011-10-31 Thread Peter Otten
Joel Montes de Oca wrote: > def UserChoice (): # The function that returns the choice from the > user > while 1: > > print 'Please select (P) for paper, (R) for Rock, or (S) for > Scissors.' > choice = raw_input('What is your selection?:') > if

Re: [Tutor] Paper Rock Scissors game - User's choice not returned properly

2011-10-31 Thread Peter Otten
Alan Gauld wrote: > if choice.lower() not in ('prs'): # NB use a single string That's not a good idea. If a user accidentally enters PR (for example) your version will mistake that for a valid choice. ___ Tutor maillist - Tutor@python.org To unsub

Re: [Tutor] Paper Rock Scissors game - User's choice not returned properly

2011-10-31 Thread Wayne Werner
On Mon, Oct 31, 2011 at 1:14 PM, Marc Tompkins wrote: > > You could simplify it even further by actually using the "while": > > > def UserChoice ():# The function that returns the choice from the > user > >choice = '' > >attempt = 0 > >while choice.lower() not in ('p', 'r','s'): >

Re: [Tutor] Paper Rock Scissors game - User's choice not returned properly

2011-10-31 Thread Joel Montes de Oca
On 10/31/2011 02:14 PM, Marc Tompkins wrote: On Mon, Oct 31, 2011 at 10:57 AM, Joel Montes de Oca wrote: I came up with this to solve the problem. def UserChoice ():# The function that returns the choice from the user while 1: print 'Please select (P) for paper, (R) for R

Re: [Tutor] Paper Rock Scissors game - User's choice not returned properly

2011-10-31 Thread Alan Gauld
On 31/10/11 17:09, Joel Montes de Oca wrote: FUN MAIN | | |__ FUN A | | |_ FUN B This is how I understand it. So if I want this to work, I need FUN B to give something back to FUN A so that FUN A will have something to give back to FUN MAIN but that doe

Re: [Tutor] Paper Rock Scissors game - User's choice not returned properly

2011-10-31 Thread Joel Montes de Oca
On 10/31/2011 02:13 PM, Prasad, Ramit wrote: Just a minor note, this break is redundant. Breaks are used to exit (for/while) loops but keep control in the function. A return exits the function immediately. if choice.lower() in ('p', 'r','s'):# Converts the user's choice to lowerca

Re: [Tutor] Paper Rock Scissors game - User's choice not returned properly

2011-10-31 Thread Prasad, Ramit
Just a minor note, this break is redundant. Breaks are used to exit (for/while) loops but keep control in the function. A return exits the function immediately. if choice.lower() in ('p', 'r','s'):# Converts the user's choice to lowercase and confirms the choice is valid

Re: [Tutor] Paper Rock Scissors game - User's choice not returned properly

2011-10-31 Thread Marc Tompkins
On Mon, Oct 31, 2011 at 10:57 AM, Joel Montes de Oca wrote: > >  I came up with this to solve the problem. > > def UserChoice ():    # The function that returns the choice from the user >     while 1: > >         print 'Please select (P) for paper, (R) for Rock, or (S) for > Scissors.' >        

Re: [Tutor] Paper Rock Scissors game - User's choice not returned properly

2011-10-31 Thread Joel Montes de Oca
On 10/31/2011 11:41 AM, Joel Montes de Oca wrote: Hello everyone, I am having a little trouble with a block of code that isn't behaving the way I would expect. Maybe you can give me a hand and point where it is going wrong. The function that is not working correctly belongs to a Paper Rock

Re: [Tutor] Paper Rock Scissors game - User's choice not returned properly

2011-10-31 Thread Joel M.
On Mon, Oct 31, 2011 at 1:09 PM, Joel Montes de Oca wrote: > On Mon 31 Oct 2011 12:14:40 PM EDT, Hugo Arts wrote: > > > On Mon, Oct 31, 2011 at 4:41 PM, Joel Montes de Oca > wrote: > > > Hello everyone, > > I am having a little trouble with a block of code that isn't behaving the > way I would

Re: [Tutor] Paper Rock Scissors game - User's choice not returned properly

2011-10-31 Thread Joel Montes de Oca
On Mon 31 Oct 2011 12:14:40 PM EDT, Hugo Arts wrote: On Mon, Oct 31, 2011 at 4:41 PM, Joel Montes de Oca wrote: Hello everyone, I am having a little trouble with a block of code that isn't behaving the way I would expect. Maybe you can give me a hand and point where it is going wrong. The

Re: [Tutor] Paper Rock Scissors game - User's choice not returned properly

2011-10-31 Thread Hugo Arts
On Mon, Oct 31, 2011 at 4:41 PM, Joel Montes de Oca wrote: > Hello everyone, > > I am having a little trouble with a block of code that isn't behaving the > way I would expect. Maybe you can give me a hand and point where it is going > wrong. > > The function that is not working correctly belongs

[Tutor] Paper Rock Scissors game - User's choice not returned properly

2011-10-31 Thread Joel Montes de Oca
Hello everyone, I am having a little trouble with a block of code that isn't behaving the way I would expect. Maybe you can give me a hand and point where it is going wrong. The function that is not working correctly belongs to a Paper Rock Scissor game I am making. This particular functio