私は、プレイヤーが5つのサイコロをロールし、どのサイコロをリロールするかを選ぶような、ゲームのようなyahtzeeをプログラミングしています。Python:異なる結果を持つリスト内の真と偽の変数を繰り返します
ユーザー入力を適切に反復処理して、関数が有効であることを確認できません。
ここにいくつかのコードです:
def diceroll():
raw_input("Press enter to roll dice: ")
a = random.randint(1, 6)
b = random.randint(1, 6)
c = random.randint(1, 6)
d = random.randint(1, 6)
e = random.randint(1, 6)
myroll.append(a)
myroll.append(b)
myroll.append(c)
myroll.append(d)
myroll.append(e)
print "Your roll:"
print myroll
diceSelect()
def diceSelect():
s = raw_input("Enter the numbers of the dice you'd like to roll again, separated by spaces, then press ENTER: ")
rollAgain = map(int, s.split())
updateMyRoll(rollAgain)
def updateMyRoll(a):
reroll = []
for n in a:
if n in myroll:
reroll.append(n)
removeCommonElements(myroll, a)
print "deleting elements..."
elif n not in myroll:
print "I don't think you rolled", n, "."
diceSelect()
else:
print "I don't understand..."
diceSelect()
print "Your remaining dice: ", myroll
def removeCommonElements(a,b,):
for e in a[:]:
if e in b:
a.remove(e)
b.remove(e)
問題がdiceSelect機能ではそうです、私は唯一の真の値を入力することができますし、それが正常に動作するように、私は偽の値を入力するだけのために所望の効果を得ることができますが、最初の偽値(私はコードに基づいて理解していますが、変更したいと思います)、または真と偽の値を入力できますが、真の値に対してのみ作用しますが、偽の値は無視します。
どのようにこれらの値を反復処理して、すべての真の値を入力するようにユーザーに促すことができますか?
「希望の効果」とは何ですか? – Carcigenicate
@Carcigenicate私は不明であることをお詫びします、私は元のポストを更新します。ユーザーのすべての値が実際に元の5サイコロにあった値と一致していることを確認したいと思います。そうでない場合は、有効な値を入力するように促すように戻してください。これは、偽の値のみを入力したときに発生する動作ですが、最初に入力した誤った値のみについてユーザーに「xを押したとは思わない」と伝えます。 – Hanzy
Python2でPythonを学習する理由はありますか?最近はPython3を使うべきです –