Я делаю карточную игру, и я хотел сделать функцию, которая печатает значение карт в руке. Однако он печатает только значение последней выбранной карты.
Я пытался подсчитать стоимость карт в другой функции, отличной от той, которая использовалась для получения карты с теми же результатами.
Палуба и Переменные:
heartsCards = ["Ace of Hearts","Two of Hearts","Three of Hearts","Four of Hearts","Five of Hearts","Six of Hearts","Seven of Hearts","Eight of Hearts","Nine of Hearts","Ten of Hearts","Jack of Hearts","Queen of Hearts","King of Hearts"]
diamondsCards = ["Ace of Diamonds","Two of Diamonds","Three of Diamonds","Four of Diamonds","Five of Diamonds","Six of Diamonds","Seven of Diamonds","Eight of Diamonds","Nine of Diamonds","Ten of Diamonds","Jack of Diamonds","Queen of Diamonds","King of Diamonds"]
clubsCards = ["Ace of Clubs","Two of Clubs","Three of Clubs","Four of Clubs","Five of Clubs","Six of Clubs","Seven of Clubs","Eight of Clubs","Nine of Clubs","Ten of Clubs","Jack of Clubs","Queen of Clubs","King of Clubs"]
spadesCards = ["Ace of Spades","Two of Spades","Three of Spades","Four of Spades","Five of Spades","Six of Spades","Seven of Spades","Eight of Spades","Nine of Spades","Ten of Spades","Jack of Spades","Queen of Spades","King of Spades"]
yourCards = []
cardValue = 0
Функция пикапа:
def pickUp():
randomNum = random.randint(1,4)
global cardValue
if randomNum == 1:
temp = random.choice(heartsCards)
if heartsCards.index(temp) < 10:
cardValue =+ heartsCards.index(temp) + 1
else:
cardValue =+ 10
yourCards.append(temp)
heartsCards.remove(temp)
if randomNum == 2:
temp = random.choice(diamondsCards)
if diamondsCards.index(temp) < 10:
cardValue =+ diamondsCards.index(temp) + 1
else:
cardValue =+ 10
yourCards.append(temp)
diamondsCards.remove(temp)
if randomNum == 3:
temp = random.choice(clubsCards)
if clubsCards.index(temp) <10:
cardValue =+ clubsCards.index(temp) + 1
else:
cardValue =+ 10
yourCards.append(temp)
clubsCards.remove(temp)
if randomNum == 4:
temp = random.choice(spadesCards)
if spadesCards.index(temp) < 10:
cardValue =+ spadesCards.index(temp) + 1
else:
cardValue =+ 10
yourCards.append(temp)
spadesCards.remove(temp)
Функция CardCount:
def cardCount():
temp = 0
global cardValue
for card in yourCards:
if card.count("Ace"):
temp =+ 1
if temp == 0:
print ("The value of your cards is",str(cardValue) + ".")
if temp == 1:
print ("The value of your cards is",cardValue,"or",str(cardValue + 10) , ".")
if temp == 2:
print ("The value of your cards is",cardValue,"or",str(cardValue + 10),"or",str(cardValue + 10) , ".")
После вызова cardCount () с колодой из двух карт выводится только значение последней карты. например с колодой из 2 черв и 8 пиков, функция печатает значение как 8.