lundi 15 juin 2020

Best way to do this without so many if statements? [closed]

I'm certain that there is a better way to do this but im not sure how, I was thinking potentially switch statements but im not quite sure how to apply that in this case.:

if p1txt == "r" and p2txt == "b":
    print("p1 wins")
if p2txt == "r" and p1txt == "b":
    print("p2 wins")
if p1txt == "y" and p2txt == "r":
    print("p1 wins")
if p2txt == "y" and p1txt == "r":
    print("p2 wins")
if p1txt == "b" and p2txt == "y":
    print("p1 wins")
if p2txt == "b" and p1txt == "y":
    print("p2 wins")

if p1txt == p2txt:
    if p1txt > p2txt:
        print("p1 wins")
    else:
        print("p2 wins")

any help would be greatly appreciated

Aucun commentaire:

Enregistrer un commentaire