On 18/12/2025 18:34, Gregg Drennan via Python-list wrote:
No chatbot involved.  I was typing this on my phone in bed last night and
didn't have a Python interpreter handy that I could verify this with.  I
will certainly check this.

In any case, since verifying that a valid choice was made was made is done
in the same IF statement as the check for None, it seems to be a moot
point.

Calling lower() on None will cause an Exception so I would always recommend
making that check on any user input.

The `input` function always returns a string (`str`), so using `.lower()` or `.casefold()` on its result will always succeed.
Yes, using casefold to deal with non-ascii characters is a good point.  In
this case, we don't care what the input was if it's not one of the four
valid choices...we just treat it as invalid and prompt the player to enter
a valid choice.


On Thu, Dec 18, 2025, 8:21 AM Thomas Passin <[email protected]> wrote:

On 12/17/2025 10:43 PM, Gregg Drennan via Python-list wrote:
The other recommendation i would make is to shorten the response the
player
needs to give when choosing their option.  "R", "P", "S" is sufficient to
determine the player's choice.  Making the player enter the whole word
introduces opportunity for misspellings.  I would also allow the player
to
enter "Q" in case they decide to stop playing.  And always check to make
sure the player entered something and didn't just hit enter.  Also don't
use .lower() until you check to make sure you have a valid entry, the
player might enter a character that can't be converted to lower case,
like
a number or punctuation.
See, here's the problem with relying on a chatbot. Calling lower() works
fine for a character that doesn't have a lowerclass version.  It just
returns the original.


while True:
      player_choice = input("Please enter your choice (Rock, Paper,
Scissors,
or Quit): "
      If not player_choice or player_choice[0] not in "RPSQrpsq":   #
check
if None or invalid choice
          print("Invalid choice...")
      else:
          If player_choice[0].lower() == "q":
               print("Thanks for playing.  Good-bye.")
               break
          # code to score the choices, blah, blah, blah

Good luck with your new version!

On Mon, Dec 8, 2025, 5:37 PM John Smith via Python-list <
[email protected]> wrote:

Thanks for the recommendations. I'm building a whole new version based
on
the old one, with simpler code and functions to find win stats.
--
https://mail.python.org/mailman3//lists/python-list.python.org

--
https://mail.python.org/mailman3//lists/python-list.python.org


--
https://mail.python.org/mailman3//lists/python-list.python.org

Reply via email to