[Tutor] Paper Rock Scissors game - User's choice not returned properly
Joel Montes de Oca
joelmontes01 at gmail.com
Mon Oct 31 19:45:25 CET 2011
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 lowercase and confirms the choice is valid
> return choice
> break
>
>
> There is also a "continue" which is similar to a break, but instead of exiting the loop, it will start the loop code over for the next value (thus "continuing" the loop).
>
>>>> t = [ 'not this', 'do this', 'not this either', 'most definitely do this' ]
>>>> for string in t:
> ... if string.startswith( 'not' ):
> ... continue # I want to keep working with the other elements in the list
> ... print string
> ...
> do this
> most definitely do this
>>>> for string in t:
> ... if string.startswith( 'not' ):
> ... break # I want to abort the entire loop now
> ... print string
> ...
>
>
>
> Ramit
>
>
> Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
> 712 Main Street | Houston, TX 77002
> work phone: 713 - 216 - 5423
>
> --
>
> This email is confidential and subject to important disclaimers and
> conditions including on offers for the purchase or sale of
> securities, accuracy and completeness of information, viruses,
> confidentiality, legal privilege, and legal entity disclaimers,
> available at http://www.jpmorgan.com/pages/disclosures/email.
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
Awesome, thanks for the tip. I removed the break from the code.
Thanks again.
--
-Joel M.
More information about the Tutor
mailing list