[Python] How do i compare one list to another using an if statement to achieve an outcome...

Discussão em 'Python' iniciado por Stack, Abril 1, 2025.

  1. Stack

    Stack Membro Participativo

    i want to make a rock paper scissors game as im beginner python and im having an issue where i want the players results to be checked against a list to output who won based on their choice so rock,paper paper wins etc

    ive tried the if statement a few times with no success

    heres the code

    """rock paper scisiors is a game of random outcomes between 2 players
    they have 3 choices and they all beat each other in different ways
    rock beats scissors, paper beats rock, scissors beats paper
    players can choose the same object that would equal a draw and lead
    to an automatic repeat of the game
    it is usually best 2/3 to win the game"""

    import time

    PlayerOne = input("Player One what is your name : ")
    PlayerTwo = input("Player Two what is your name : ")
    options = ["Rock","Paper","Scissors"]
    RockWins = ["rock","scissors"]
    PaperWins = ["rock","paper"]
    ScissorsWins = ["scissors","paper"]
    P1Option = []
    P2Option = []

    def rockPaperScissors(first, second):
    print(f"Hi {PlayerOne} and {PlayerTwo} we will now begin a game of Rock Paper Scissors")
    P1Option = input(f" {PlayerOne} Choose your weapon!")
    P2Option = input(f" {PlayerTwo} Choose your weapon!")
    first = P1Option
    second = P2Option
    time.sleep(1)
    print("Rock")
    time.sleep(1)
    print("Paper")
    time.sleep(1)
    print("Scissors")
    time.sleep(2)
    print(f"{PlayerOne} has chosen {first} and {PlayerTwo} has chosen {second}")

    Descision = [P1Option,P2Option]

    if Descision is RockWins:
    print("Rock Wins")
    elif Descision is PaperWins:
    print("Paper Wins")
    else:
    print("Scissors Wins")
    print(Descision)

    rockPaperScissors(P1Option,P2Option)

    Continue reading...

Compartilhe esta Página