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
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'):
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
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
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
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
|
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
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
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
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
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'):
>
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
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
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
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
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.'
>
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
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
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
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
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
21 matches
Mail list logo