我试图询问用户:
如果他们打出一张A,问他们是想要1还是11。
他们回答一个整数,这意味着要设置为1或11。不幸的是,当我运行时,这仍然是王牌。你知道吗
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。你知道吗
将数字1或11赋给
cards[0]
,但这不会更改newcardtype
引用的对象或值,因此它仍然具有值'ace'
。如果要更改newcardtype
的值,还必须为其赋值1或11。你知道吗相关问题 更多 >
编程相关推荐