只是单挑:我对python很新 无论如何,这就是我设置我的套牌的方式:
// Code goes here
var Button = React.createClass({
render: function() {
return ( < button > Go < /button>)
}
});
React.render( < Button / > , document.getElementById("root"));
之后,我会输入:
#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
这将是随机输出由于shuffle函数每次都不同(还有一个print语句,但我没有包含它):
create_hands(deck)
现在,这基本上就是list_hand的列表,但是当我接着进行检查时:
('10', 'diamond', '2', 'diamond')
输出:
player_hand
我很困惑因为不应该让player_hand返回与create_hands函数相同的值,假设我只运行了create_hands(deck)一次?
答案 0 :(得分:0)
你的
player_hand
具有随机生成的本地范围,而
create_hands
具有全局范围,您可以在外部访问它 - 而且,每次调用都会生成不同的结果,因此每次您测试其中任何一个时,您将获得不同的结果
random.shuffle(deck)