我想问一个用户:
如果他们画了一张王牌,问他们是否希望它是1或11。
他们回答一个整数,将它设置为1或11是很重要的。不幸的是,当我运行时,它仍然是ace。
import time
import random
from random import *
suits = ["Hearts","Diamonds","Clubs","Spades"]
cards = ["Ace","2","3","4","5","6","7","8","9","10","Jack","Queen","King"]
def drawcard():
global newcardtype
global newcardsuit
global newcard
newcardtype = cards[randint(0,11)] ##User interface & Console
newcardsuit = suits[randint(0,3)] ##User interface & Console
newcard = newcardtype, newcardsuit ##Console to read and understand
print("You picked up: " + str(newcardtype) + " of " + str(newcardsuit) + ".")
suits[0] = "♡"
suits[1] = "♢"
suits[2] = "♧"
suits[3] = "♤"
cards[10] = 10
cards[11] = 10
cards[12] = 10
while(True):
test = input("New card? ")
if test == "y":
drawcard()
if newcardtype == cards[0]:
acequestion = int(input("You picked up an Ace. Would you like your Ace to be 1 or 11?: "))
if acequestion == 1:
cards[0] = int(1)
if acequestion == 11:
cards[0] = int(11)
print(newcardtype)
它处于正常工作状态,但我想cards[0]
根据“acequestion”问题的答案,“ace”等于1或11。
答案 0 :(得分:2)
您要将号码1或11分配给cards[0]
,但这不会更改newcardtype
引用的对象或值,因此它仍然具有值'ace'
。如果您想更改newcardtype
的值,您还必须为其分配1或11。