1
我試着製作一個簡單的骰子滾動程序,我可以讓骰子'滾動',但我無法阻止它,它只會保持,如果你輸入任何東西。我試圖添加它,所以如果你說'不'或'n'返回並像往常一樣去我的其他功能。我說回來是因爲繼續我的其他代碼很重要。謝謝。循環不退出,如果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'。請注意,檢查也可以像''如果roll_more.lower()in ['yes','y']完成:'以節省空間並確保使用小寫字母。您的代碼會將「否」的值理解爲「是」。 –