dimanche 30 décembre 2018

How to put my own function in side an if statement?

I am trying to make a simple blackjack game and i want to be able to create my own function, which a can already do, and then put it inside an if statement so that if the user want's to 'stand' then it runs the function to 'stand'. However, when python reads through the code, even if the user say 'Hit', it see's all the functions and just runs all of them.

def stand():
    print("You have chosen to Stand")
    #my stand code will go here
def hit():
    print("You have chosen to Hit")
    #my Hit code will go here
def doubledown():
    print("You have chosen to Double Down")
    #my Double Down code will go here
def step():
    step = input("What would you like to do now? Stand, Hit or Double Down")
    if step == ("Stand") or ("stand"):
        stand()
    if step == ("Hit") or ("hit"):
        hit()
    if step == ("Double down") or ("down"):
        doubledown()
    else:
        step()
step()

I would like the user to be able to run the 'Hit', 'double down' or 'stand' function 1 at a time without all of them running.

Aucun commentaire:

Enregistrer un commentaire