Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/301.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 将整数赋给列表_Python_Python 3.x_If Statement_Variable Assignment - Fatal编程技术网

Python 将整数赋给列表

Python 将整数赋给列表,python,python-3.x,if-statement,variable-assignment,Python,Python 3.x,If Statement,Variable Assignment,我正试图询问用户: 如果他们得了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 dr

我正试图询问用户:
如果他们得了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。

int(1)
??“杀伤力太大了。”让·弗朗索瓦·法布可能是这样,但我想安全,而不是后悔。我是python新手,我想确保它能正常工作,这样我就不会对Ned Batcheld的演讲感到困惑。