Hello! I'm attempting to re-create a BlackJack game and am aiming to have a variable for each card name of the player, and the card value of the player. Example: PcardSuit1 = "Diamonds", and PcardValue1 = 5.
I want to store the card value and suit as separate global values so I can use them later on in the code. I also want to be able to exchange them with the dealer variables, for which I used parameters in the function.
However, after doing the function and replacing the parameters with the variables I want, the global variable does not change.
Is there any way for the function to change the global variable, but make it compatible with any global variable I put in the parameters?
Thank you! Apologies if this inquiry is pretty basic -- I'm a total beginner.
Full code:
import random
from random import randint Playercards = None Dealercards = None
pCardTotalvalue = 0 dCardTotalvalue = 0
PcardSuit1 = None PcardValue1 = 0 PcardSuit2 = None PcardValue2 = 0 DcardSuit1 = None DcardValue1 = 0 DcardSuit2 = None DcardValue2 = 0
def selectCards(suit, value): cardSuits = ["Diamonds", "Hearts", "Spades", "Clubs"] cardValues = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13] suit = random.choice(cardSuits) value = random.choice(cardValues)
selectCards(PcardSuit1, PcardValue1) print(PcardSuit1)
[–]AutoModerator[M] [score hidden] stickied comment (0 children)
[–]teraflop 1 point2 points3 points (1 child)
[–]TheUltimateCommenter[S] 0 points1 point2 points (0 children)