【发布时间】:2021-04-30 21:40:31
【问题描述】:
我正在尝试制作二十一点游戏
在 if 和 elif 语句之前一切正常...
如果您在代码平台中尝试此代码,您将在 if 块中看到“new_user_card”是无类型..
这是为什么呢?
elif 块也一样
提前致谢!
import random
cards = [11, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10]
def hand():
user_cards = random.sample(cards, 2)
print(f"Your cards are : \n {user_cards}")
computer_cards = random.sample(cards,1)
print(f"Computer's first card {computer_cards}")
more = input("Do you want to draw another card? Type 'y' for yes and 'n' for no : ")
if more == "y":
new_user_card = print(random.choice(cards))
user_cards.append(new_user_card)
print(f"Your cards are : \n {user_cards}")
elif more == "n":
computer_new_card = print(random.choice(cards,1))
computer_cards.append(computer_new_card)
print(f"Computer's has been dealt the second card.\n Computer's cards are {computer_cards}")
return user_cards
return computer_cards
hand()
【问题讨论】:
标签: python python-3.x blackjack