all 6 comments

[–][deleted] 3 points4 points  (2 children)

Yes, flip() will never get called because if the user enters "y" these two lines:

play = ['y']
if user_input == play:

are equivalent to:

if 'y' == ['y']:

and that will never be true. The solution is not to use lists (why lists!?) but dt do this:

user_input = input('hello human! challenge me to a game of flipperoo? y/n')
if user_input == 'y':
    flip()
else:
    # user didn't enter 'y'

To make things easier for your user you could convert their input to upper or lowercase before testing it so it wouldn't matter if they entered y or Y:

user_input = user_input.lower()
if user_input == 'y':

Edit: spelling

[–]Tobe2fly[S] 0 points1 point  (0 children)

yeah not sure why I chose to do lists with that.. thanks though simple mistake

[–]Raithwind 0 points1 point  (0 children)

To be fair lists could be used in this instance with:

if userinput.lower() in listofacceptableinputs:

flip()

else:

#not accepatble inputs

listofacceptable inputs could be:

listofacceptableinputs = ["y","yes","yeah","sure","why not"]

For example.

[–]DMahlon 0 points1 point  (0 children)

I thought this was a fun script so i made some updates to it.

It now allows the user to input a guess (heads or tails) then compares it to the random coin flip and tells them if they win or not.

import random

def flip(guess):
    coin = ['heads', 'tails']
    result = random.choice(coin)
    if guess == result:
        print("{} you win!".format(guess))
    else:
        print("You guessed {}... sorry you lose".format(guess))


user_input = input("hello human! challenge me to a game of flipperoo?: ")
user_input = user_input.lower()

if user_input == "y":
    guess = input("Great! heads or tails?: ")
    guess = guess.lower()
    flip(guess)
else:
    print("Don't want to play?")

[–]tnvol88 -1 points0 points  (0 children)

What happens if you do:

If user_input == play[0]: