TypeError:deckcards()缺少1个必需的位置参数:“trumps”

2024-09-28 05:23:13 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在做一个顶级王牌游戏,想得到一个局部变量在不同的函数中使用。这是所有必要的代码。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 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()

Tags: 函数from游戏numberhelloifdef顶级
1条回答
网友
1楼 · 发布于 2024-09-28 05:23:13

要将变量作为函数参数传递给第二个函数。你可能想看看这个https://www.pythoncentral.io/fun-with-python-function-parameters/

例如:

def deck_cards(num_cards):
  cards = num_cards // 2
  print(cards)

num \u cards是通过调用deck \u cards传递的参数(52)

相关问题 更多 >

    热门问题