gpt4 book ai didi

python - 将整数分配给列表

转载 作者:行者123 更新时间:2023-12-01 02:34:56 25 4
gpt4 key购买 nike

我正在尝试询问用户:
如果他们抽到了一张 A,询问他们想要是 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)

它处于工作状态,但我希望根据“acequestion”问题的答案,“ace”的 cards[0] 等于 1 或 11。

最佳答案

您将数字 1 或 11 分配给 cards[0],但这不会更改 newcardtype 引用的对象或值,因此它仍然值为'ace'。如果您想更改 newcardtype 的值,您还必须为其分配 1 或 11。

关于python - 将整数分配给列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46359466/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com