我正在嘗試創建一個接受輸入並將轉換任何輸入的程序,例如,是/是以小寫形式在下面的while循環中被接受。我試圖做到這一點,但沒有奏效。任何想法?將輸入轉換爲小寫以便在while循環中接受
#Import the random function - This only needs to be imported once.
import random
#Use a while loop to allow the user to repeat the process
repeat = "YES"
while repeat == "yes":
#User is able to input which sided dice they want to throw.
dice = input("What side dice do you want to use? 4, 6, or 12?\n")
#4 sided
if dice == "4":
#Outputs what sided dice has been chosen and the score thay they rolled.
print(dice, "sided dice chose.\nYou rolled a", random.randint(1,4))
#6 sided
elif dice == "6":
print(dice, "sided dice chose.\nYou rolled a", (random.randint(1,6)))
#12 sided
elif dice == "12":
print(dice, "sided dice chose.\nYou rolled a", (random.randint(1,12)))
#Incorrect value entered
else:
#Informs the user that the number they have chosen is not a valid option.
print(dice, "is not a valid choice")
#Asks user if they want to use the program again.
print("Do you want to use the program again? Yes or No?")
#Links back to the start of the while loop.
repeat = input()
'輸入()運行。低()' –
這似乎是一個問題你的重複初始值是大寫;) – GreenAsJade
你嘗試了什麼?您在發佈的代碼中不會顯示您的嘗試。 – user2357112