0
只是擡頭:我是相當新的Python 無論如何,這是我如何設置我的甲板:問題創造了2張牌出52張牌酒杯的〜爲Python
#THIS IS THE DECK ITSELF
signs = ["spade","hearts","club","diamond"]
num=['A','2','3','4','5','6','7','8','9','10','J','Q','K']
deck = [(j,i) for j in num for i in signs]
#Step 1. creates 2 random 2-card hands (you and dealer)
#and shows you your hand and only one card of dealer's hand
import random
def create_hands(deck):
random.shuffle(deck)
print ("You got:")
print (deck[0][0], "of", deck[0][1])
print (deck[1][0], "of", deck[1][1])
print ("Dealer has:")
print (deck[2][0], "of", deck[2][1])
print ("unknown")
player_hand = (deck[0]+deck[1])
return player_hand
之後,我就進入:
create_hands(deck)
,這將是隨機輸出由於隨機播放功能(也有一個print語句,但我並沒有包括它)每一次不同的是:
('10', 'diamond', '2', 'diamond')
012現在
,這是基本的列表player_hand是什麼,但是當我再繼續把這個檢查:
player_hand
它輸出:
('4', 'club', 'J', 'spade')
我很困惑,因爲不應該」 t player_hand返回與create_hands函數相同的值,假設我只運行一次create_hands(deck)?
你如何建議我解決這個問題這樣player_hand就等於從create_hands返回的內容? –
是的,您只關心函數返回的內容,因爲函數內部可能會在下次有所不同,所以忽略它。 – dmitryro