I’ve been trying to make a simple blackjack game in python and I seem to be stuck, my code is as follows:
from random import choice
def deck():
cards = range(1, 12)
return choice(cards)
def diack():
card1= deck()
card2 = deck()
hand = card1 + card2
print hand
if hand < 21:
print raw_input("Would you like to hit or stand?")
if "hit":
return hand + deck()
elif "stand":
return hand
When I run that it seems to work for “hit” but when I type in “stand” it seems to “hit” aswell. As you can probably tell by now I am extremely new to programming. Could you guys help point me in the right direction on how to make my game work (I’d like to use as much of my code as possible).
if "hit"just tests if the string"hit"exists, and it does. Thus, theelifstatement is never executed.You need to capture the user input in a variable and test against that instead: