我想在python中做一個二十一點遊戲。我遇到了一個問題,因爲我試圖在遊戲中使用隨機模塊。我使用隨機模塊獲取與列表中的索引號相匹配的數字。我做的名單包括卡片面值。但我不知道如何使用隨機索引號打印這些值。這裏是我的代碼:如何用Python 2.7中的索引號打印列表中的值?
# this is a blackjack game made in python
import random
import time
# make a list full of the card values
cards = (["A", "K", "Q", "J", 2, 3, 4, 5, 6, 7, 8, 9, 10])
indexNum1 = random.randint(0,12)
indexNum2 = random.randint(0,12)
indexNum3 = random.randint(0,12)
indexNum4 = random.randint(0,12)
indexNum5 = random.randint(0,12)
for card in cards:
print card(indexNum1)
print card(indexNum2)
print card(indexNum3)
print card(indexNum4)
print card(indexNum5)
我希望有人能幫我解決這個問題。謝謝!
謝謝AChampion。我將如何在代碼中使用它? –