Rock Paper Scissors! <Python/>

Rock Paper Scissors! <Python/>

·

1 min read

#importing random module
import random

#making a infinite loop
c = 0
while c<1:

    #declaring function
    def game(a,b):

        #condition for tie
        if a == b:
            return None

        elif a == "R":
            if b == "P":
                return True 
            elif b == "S":
                return False


        elif a == "P":
            if b == "S":
                return True 
            elif b == "R":
                return False


        elif a == "S":
            if b == "R":
                return True 
            elif b == "P":
                return False


    #generating random number
    a = random.randint(1,3)

    #conditioning the numbers
    if a == 1:
        a = "R"

    if a == 2:
        a = "P"

    if a == 3:
        a = "S"

    #asking input from the user.
    x = input("Your Turn: ")

    #transforming the input to uppercase
    b = x.upper()


    #passing the variables
    result = game(a,b)

    #computing the results
    if result == None:
        print("You Tied!")

    elif result:
        print("You Won!")
    else:
        print("You Lost!")

    #printing the computers move
        print(f"Computer Choosed {a}.")