私はシンプルなダイスローリングプログラムを作ろうとしましたが、私はサイコロを「ロール」にすることはできますが、止めることはできません。私はそれを追加しようとしたので、もしあなたが 'いいえ'または 'いいえ'と言うなら、それはに戻ります。そしていつものように私の他の機能に行きます。私は他のコードへの継続が重要なので、私はリターンを言う。ありがとうございました。roll_more == 'no'の場合ループが終了しない
import random
min = 1
def rolling6():
roll_more = "yes"
while roll_more == "yes" or roll_more =="y":
max = 6
print("Rolling the dices...")
print("The values are...")
print(random.randint(min, max))
print(random.randint(min, max))
roll = input("Roll the die again? ")
if roll_more == "no" or roll_more == "n":
return
#roll_again = "yes"
#while roll_again == "yes" or roll_again =="y":
# print("Rolling the dices...")
# print("The values are...")
# print(random.randint(min, 6))
# print(random.randint(min, 6))
# roll_again = input("Roll the die again? ")
#if roll_again == "no" or roll_again == "n":
# return
x = input("Use six sided die? ")
while x == "yes" or x =="y":
rolling6()
ユーザー入力は変数 'roll'に割り当てられ、' roll_more'をチェックしています。スペースを節約し、小文字が使用されていることを確認するには、['yes'、 'y']: 'のroll_more.lower()のようにチェックを行うこともできます。 'No'の値はコードによって' yes'と解釈されます。 –