lundi 25 octobre 2021

Python rock, paper, scissors, problem with else/elif statements

I am trying to make a rock, paper, scissors game, but I think I am doing something wrong with the else/elif statements.

import random
list = ['R', 'P', 'S']

def play():
    x = input('Please input R, P, or S: ').upper()
    y = random.choice(list)
    if x == y:
        print('You both picked {}, pick again'.format(x))
        play()
    elif (x == 'r' and y == 's') or (x == 'p' and y == 'r') or (x == 's' and y == 'p'):
        print('You won! You picked {} and computer picked {}'.format(x,y))
    else:
        print('You lost. You picked {} and computer picked {}'.format(x,y))

play()

Aucun commentaire:

Enregistrer un commentaire