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

Prasad, Ramit ramit.prasad at jpmorgan.com
Mon Oct 31 19:13:53 CET 2011

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

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 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.  

More information about the Tutor mailing list