Python TypeError:deckcards()缺少1个必需的位置参数:';特朗普';
我正在制作一个顶级特朗普游戏,希望在不同的函数中使用一个局部变量。这是所有必要的代码。hello()是菜单,但与此处无关Python TypeError:deckcards()缺少1个必需的位置参数:';特朗普';,python,python-3.x,Python,Python 3.x,我正在制作一个顶级特朗普游戏,希望在不同的函数中使用一个局部变量。这是所有必要的代码。hello()是菜单,但与此处无关 def deckcards(): cards = trumps.cards // 2 print(cards) def trumps(): cards = int(input("""How many cards would you like? (Even number from 4, 30): """)) if cards % 2 == 0 and ca
def deckcards():
cards = trumps.cards // 2
print(cards)
def trumps():
cards = int(input("""How many cards would you like?
(Even number from 4, 30): """))
if cards % 2 == 0 and cards != 0:
if cards < 4 or cards > 30:
print("Please enter an even number from 4 to 30")
hello()
else:
deckcards()
else:
print("Invalid amount.")
hello()
def deckcards():
卡片=王牌。卡片//2
打印(卡片)
特朗普():
cards=int(输入(“”)您想要多少张卡?
(4,30中的偶数):“”)
如果卡片%2==0且卡片!=0:
如果卡数小于4或卡数大于30:
打印(“请输入4到30之间的偶数”)
你好()
其他:
纸牌
其他:
打印(“无效金额”)
你好()
您希望将变量作为函数参数传递给第二个函数。你可能想看看这个
例如:
def deck_cards(num_cards):
cards = num_cards // 2
print(cards)
num_cards是通过调用deck_cards(52)传递的参数。您的代码不完整。我们看不到什么是
胜过。我们看不到什么是王牌。你为什么不从deckcards()
返回王牌/2
呢。了解。避免全局性,传递所需的函数参数。确保在问题正文中以文本形式显示错误和回溯。不要隐藏标题中的错误。