0

I want to display "Invalid Entry" when the user selects an incorrect choice, but my program displays this message regardless of what the user types in. I can't seem to figure it out, could someone help me out?

Also, how would I rewrite this program so it would print out what the computer and user selected? I was able to get it so it printed out

User: 'P' | AI: 'R'

but I want it to display "Paper" and "Rock" instead

My code:

import random


def vs_AI():

    ai_pick = random.choice(['P', 'S', 'R'])
    user_pick = input("'P' for paper, 'R' for rock, 'S' for scissors: ").upper()

    while user_pick != ('P' or 'R' or 'S'):
        print("Invalid entry!")
        user_pick = input("'P' for paper, 'R' for rock, 'S' for scissors: ").upper()

    if user_pick == ai_pick:
        return 'Tie!'

    if win(user_pick, ai_pick):
        return 'Congrats! Winner!'

    return 'You lose!'


def win(user_pick, ai_pick):
    if (user_pick == 'P' and ai_pick == 'R') or (user_pick == 'R' and ai_pick == 'S') or (user_pick == 'S' and ai_pick == 'S'):
        return True


start = input("Play? (Y/N): ").upper()
while start == 'Y':
    print(vs_AI())
    start = input("Play again? (Y/N)").upper()
print("Game ended.")
CocoPun
  • 15
  • 5

0 Answers0