我正在做一个顶级王牌游戏,想得到一个局部变量在不同的函数中使用。这是所有必要的代码。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()
要将变量作为函数参数传递给第二个函数。你可能想看看这个https://www.pythoncentral.io/fun-with-python-function-parameters/
例如:
num \u cards是通过调用deck \u cards传递的参数(52)
相关问题 更多 >
编程相关推荐