Okay, so I know you shouldn't /really/ make variables global - they're meant to be local. However I am programming a blackjack game and I need to reset the cards every time the user wants to play again - so I have made a function called 'reset' and it calls that if the it is going to repeat. My main question is, should I do this or is there a better method of solving my problem, or is there a better way of doing this than just typing out global _____ every time? Here's my code if anyone wants to see;
import random
playagain = True
def reset():
global cards
global gameCards
global playerCards
global cpuCards
global pgameCards
global cpugameCards
global start
cards = ["A♠", "2♠", "3♠", "4♠", "5♠", "6♠", "7♠", "8♠", "9♠", "10♠", "J♠", "Q♠", "K♠",
"A♥", "2♥", "3♥", "4♥", "5♥", "6♥", "7♥", "8♥", "9♥", "10♥", "J♥", "Q♥", "K♥",
"A♣", "2♣", "3♣", "4♣", "5♣", "6♣", "7♣", "8♣", "9♣", "10♣", "J♣", "Q♣", "K♣",
"A♦", "2♦", "3♦", "4♦", "5♦", "6♦", "7♦", "8♦", "9♦", "10♦", "J♦", "Q♦", "K♦"]
gameCards = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10,
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10,
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10,
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10]
playerCards = []
cpuCards = []
pgameCards = []
cpugameCards = []
start = 0
[...]
while playagain == True:
reset()
winner = game()
print("Your cards: ", playerCards)
print("CPU's cards: ", cpuCards)
print(winner)
askUser = input("Play again? Y/N ")
if askUser.upper() == "Y":
playagain = True
else:
playagain = False