The code works mostly well, however, after trying the play again command I made it exits the program and doesn't cycle as expected. The code causing issues is below.
play_again = 'y' or 'n'
draw_again = 'hit' or 'hold'
print("This is a simple game of blackjack. The main objective is to stay under or equal to 21 in value.")
print("Number cards are worth their number. Face cards are worth 11. Aces are worth either 1 or 11")
print("If you want to draw again type hit. To finish type hold.")
play_game = input("would you like to play? (y/n):")
if play_game == 'y':
shuffleDeck()
print ("your starting hand is")
drawFaceUp()
drawFaceUp()
draw_again = input("hit, or hold (hit/hold):")
while draw_again == 'hit':
print("your next card is")
drawFaceUp()
draw_again = input("hit, or hold (hit/hold):")
if draw_again == 'hold':
score = input("Enter your score <score number>:")
if score <= '15':
print("good job, but try and get a little closer to 21 next time")
play_again = input("Play again? (y/n):")
if play_again == 'y':
newDeck()
shuffleDeck()
print ("your starting hand is")
drawFaceUp()
drawFaceUp()
draw_again = input("hit, or hold (hit/hold):")
while draw_again == 'hit':
print("your next card is")
drawFaceUp()
draw_again = input("hit, or hold (hit/hold):")
if draw_again == 'hold':
score = input("Enter your score <score number>:")
elif play_again == 'n':
print ("end of program")
elif score > '15' and score < '21':
print("Nice. you should test you luck again.")
play_again = input("Play again? (y/n):")
if play_again == 'y':
newDeck()
shuffleDeck()
print ("your starting hand is")
drawFaceUp()
drawFaceUp()
draw_again = input("hit, or hold (hit/hold):")
while draw_again == 'hit':
print("your next card is")
drawFaceUp()
draw_again = input("hit, or hold (hit/hold):")
if draw_again == 'hold':
score = input("Enter your score <score number>:")
elif play_again == 'n':
print("end of program")
elif score == '21':
print("you got a perfect score. see if you can do it again.")
play_again = input("Play again? (y/n):")
if play_again == 'y':
newDeck()
shuffleDeck()
print ("your starting hand is")
drawFaceUp()
drawFaceUp()
draw_again = input("hit, or hold (hit/hold):")
while draw_again == 'hit':
print("your next card is")
drawFaceUp()
draw_again = input("hit, or hold (hit/hold):")
if draw_again == 'hold':
score = input("Enter your score <score number>:")
elif play_again == 'n':
print("end of program")
elif play_game == 'n':
print("end of program")
I expect the game to be able to endlessly cycle until told not to. the actual output causes the game to close after 2 rounds of playing.