此代码无法正常工作

时间:2018-09-13 08:34:31

标签: python python-3.x

cards_in_deck= ['A','A','A','A','2','2','2','2','3','3','3','3','4','4','4','4','5','5','5','5','6','6','6','6','7','7','7','7','8','8','8','8','9','9','9','9','10','10','10','J','J','J','J','K','K','K','K','Q','Q','Q','Q']
def card_selection(generated):
    global tempvalue
    if generated == 'A':
        temp=input("You want to use 1 or 11\n")
        tempvalue=temp
    elif generated == '2' or '3' or '4' or '5' or '6' or '7' or '8' or '9':
        tempvalue= generated
    else:
        tempvalue = 10
    return int(tempvalue)
temp_card = random.choice(cards_in_deck)
print(temp_card)
card_selection(temp_card)
print(tempvalue)

我正在构建一个脚本,该脚本从卡组中随机拾取一张卡片,如果该卡片是'A',则值将为111。如果该卡为'J''q''K''10',则值为10;如果该卡为2,3,4,5,6,7,8,9,则值为会一样。

我面临的问题是,脚本对于'A'和2到9的数字都适用,但是每当生成'j'或'q'或'k'时,我都会报错,

ERROR MESSAGE::ValueError: invalid literal for int() with base 10: 'K'.

由于我是python的新手,所以对孩子的代码感到抱歉,任何帮助和建议都将被高度接受。提前致谢。希望你能帮助我! :)

0 个答案:

没有答案