Feb-23-2021, 03:40 AM
(This post was last modified: Feb-23-2021, 03:41 AM by deanhystad.)
Your code is upside down. Instead of a function that asks if you want to play again you should have a function that plays the game.
import random choices = "RPS" win = {"R":"S", "P":"R", "S":"P"} throws = {"R":"Rock", "P":"Paper", "S":"Scissor"} def get_input(prompt, choices): """Get user input. Repeat until valid input is entered.""" while True: choice = input(prompt).upper() if choice in choices: return choice def play_game(): """Play Rock Paper Scissor against computer until there is a winner.""" while True: computer = random.choice(choices) player = get_input("\nChoose [R]ock, [P]aper or [S]cissor: ", choices) if player == computer: print(f"Computer throws {throws[computer]}. Draw!") elif win[player] == computer: print(f"Computer throws {throws[computer]}. You Win!") break else: print(f"Computer throws {throws[computer]}. You lose.") break # Play until player wants to quit while True: play_game() if get_input("\nDo you want to play again? [Y,N]", "YN") != "Y": breakSince user input figures so importantly in the game I wrote a function to simplify getting valid input.