On 12/8/2025 2:49 PM, John Smith via Python-list wrote:
Thanks for the tip. I'll do that here and in future games.

In addition to using constants to parameterize the strings, the whole game can be made simpler and easier to change when you realize that the if/else block has a regular construction. Here's a sketch of one way to take advantage of this structure (untested). You should be able to fill in the elided code. Use lower case to check the input so a mistake in capitalization doesn't reject the input. That's a simple courtesy to the user.

import random #Allows for a random input.

ROCK = 'rock'
PAPER = 'paper'
SCISSORS = 'scissors'
TIE = 'Tie'
ULOSE = 'You Lose'
UWIN = 'You Win'

GAME = {
    (ROCK, ROCK): TIE,
    (ROCK, PAPER): ULOSE,
    # ...
}

OPTIONS = (ROCK, PAPER, SCISSORS)
PROMPT = (f'Welcome to the {ROCK}, {PAPER}, {SCISSORS} game. ' +
        'Choose one of the three')

# skipping some code
    player_choice = input(PROMPT)
    player_choice = player_choice.lower()
    if player_choice not in OPTIONS:
        print(f'{player_choice} is not an allowed input')
        continue
    result = GAME[(player_choice, choice)]
    print(result)
    # ...




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

Reply via email to