I'm doing online python course and they asked to code Blackjack game. I have a problem with function that check score on dealers hand. I checked it with "Thonny" step by step and seems to be working until if >= 17 is true. "Thonny" shows me returned value from if statement and... here magic happens. It jumps straight to else block and prints("why is this showing up?") as many times as function was appending "cards". Then both prints at the very bottom gives: <class 'NoneType'> and: None as returned value. If I remove comment from return in else block, then again it iterates backwards as many times as function was appending "cards" and returns initial value of dealer_hand list, 2 in this case. (print statements are for feedback only)
import random
cards = [11, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10]
dealer_hand = []
def value_check(hand):
card_sum = sum(hand)
return card_sum
def card_draw():
card = random.choice(cards)
return card
def dealer_val_check(hand):
value = value_check(hand)
if value >= 17:
return value
else:
hand.append(card_draw())
print(hand)
dealer_val_check(hand)
# return value
print("why is this showing up?")
dealer_hand = [1, 1]
dealer_value = dealer_val_check(dealer_hand)
print(type(dealer_value))
print(dealer_value)