當被問到時,Python不會將我的變量Ace,Jack,Queen或King更改爲10,而是似乎跳過while循環並繼續前進。Python拒絕更改變量
我正在使用python 3.5。
Ace = "Ace"
Jack = "Jack"
Queen = "Queen"
King = "King"
x = [Ace, 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King, Ace]
x1 = random.choice(x)
x2 = random.choice(x)
# this array is irrelevant to the question.
suit = ["Spades", "Hearts", "Diamonds", "Clubs"]
suit1 = random.choice(suit)
suit2 = random.choice(suit)
while suit1 == suit2:
suit2 = random.choice(suit)
Ace = "Ace"
Jack = "Jack"
Queen = "Queen"
King = "King"
while x1 == ["Jack", "Queen" , "King"]:
x1 == 10
while x2 == ["Jack" , "Queen" , "King"]:
x2 == 10
print ("Your cards are the " + str(x1) + " of " + str(suit1) +
" and the " + str(x2) + " of " + str(suit2))
print (str(x1) + " " + str(x2))
# When it tries to add the two variables here, it comes up with an error,
# as it cannot add "King" to "10", since "King" is not a number.
total = (int(x1) + int(x2))
該代碼沒有什麼意義,我認爲你需要有一個教程,刷(如[Python官方教程]( https://docs.python.org/3.6/tutorial/index.html))。 – TigerhawkT3
您的x1,x2變量被隨機設置爲一張卡片。他們不可能等於三張牌的名單!也許你想''在[傑克,女王,國王]''x1。測試應該是「if」,而不是「while」。 – jasonharper
我投票關閉這一問題作爲題外話,因爲SO不是教程服務。 – TigerhawkT3