私は現在、ランダムカードゲームプロジェクトを行っています.プログラムは5ランダムカードをユーザーに表示する必要があります.(最初の質問):文字のリストをランダムにする方法がわかりません.コードは次のとおりです.
def play():
hand = ["A","2","3","4","5","6","7","8","9","T","J","Q","K"]
for i in range(len(hand)):
card = random.choice[{hand},4]
print "User >>>> ",card
return card
2 番目の質問: ユーザーがカードの位置を変更したい場合。ユーザーは no を入力する必要があります。位置変更の場合、プログラムはカードをランダムに変更する必要があります。例: AJ891、ユーザー入力: 1、 --> A2891。私は何をすべきか?これが私の元のコードですが、うまくいきません
def ask_pos():
pos_change = raw_input("From which position (and on) would you want to change? (0 to 4)? ")
while not (pos_change.isdigit()):
print "Your input must be an integer number"
pos_change = raw_input("From which position (and on) would you want to change? (0 to 4)? ")
if (pos_change > 4) :
print "Sorry the value has to be between 0 and 4, please re-type"
pos_change = raw_input("From which position (and on) would you want to change? (0 to 4)? ")
return pos_change
hand = ["A","2","3","4","5","6","7","8","9","T","J","Q","K"]
for i in range(len(hand)):
card = random.choice[{hand},4]
new = random.choice[{hand},1]
for i in range(len(card)):
if (card[i] == pos_change):
card = card + new
return card