i have a noob question. I'm trying to make a blackjack and in my "turn" function i put a variable change to False. I have no clue why it doesnt work... It says local variable is never used, but how's that possible if it is used in the while loop...
import random
p1 = []
p2 = []
cards = [11, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10]
# --------------------Game on/off
game_on = True
# -----------------Random card
def pick_card(x):
return x.append(random.choice(cards))
# ---------------- calculate score :
def calculate_score(x):
if len(x)==2 and sum(x) ==21:
return 0
if sum(x)>21:
if x.count(11):
x.remove(11)
x.append(1)
return sum(x)
return sum(x)
# ------------------------
def turn(x):
pick_card(x)
if calculate_score(x) == 0:
print("blackjack")
game_on= False
elif calculate_score(x) >21:
print("You lost")
game_on= False
else:
print(p1)
pick_card(p1)
pick_card(p2)
pick_card(p2)
while game_on:
turn(p1)
if input("continue?\n") == "y":
game_on = True
else:
game_on=False