vendredi 3 avril 2020

Heads or Tails in Python

The if and elif conditions aren't working and I am not even getting an error. The code is intended to match the users input to what the computer selects and then make a call, if the user won or lost.

import random

def flip():
    return random.choice(["Heads", "Tails"])


Users_Selection = (input("Choose: Heads or Tails?"))

print("Flipping the coin. Please wait!")


print ("It a", flip())


if flip()=="Heads" and "Heads"==Users_Selection:
        print("Congratulations, you won!")

elif flip()=="Tails" and "Tails"==Users_Selection:
        print("Sorry, You lose! Please try again")

All help is genuinely appreciated!

Aucun commentaire:

Enregistrer un commentaire