2016-04-27 40 views
1

我正在製作一個和跳舞革命一樣的遊戲,或者更多的吉他英雄。按下屏幕上顯示的鍵盤上的相應按鍵。我已經使這個函數得到了鍵的輸出,但是現在我需要把輸出作爲另一個函數的輸入。我認爲這需要語法,'返回'只是不知道如何去做。這是我目前的代碼。Python/Pygame:你如何從函數獲取輸出並將其用作另一個函數的輸入?

def randArrow(): 

    randArrow = ['left', 'right', 'down', 'up'] 

    for direction in 'randArrow': 
     print(random.choice(randArrow)) 

    return randArrow 

回答

1

服用一個函數的輸出,並把在另一個示例:

def get_value(): 
    return 5 

def print_value(x): 
    print(x) 

temporary_variable = get_value() 

print_value(temporary_variable) 

或更好:

def get_value(): 
    return 5 

def print_value(x): 
    print(x) 

print_value(get_value()) 
0

如果你有一個功能printFirstArrow是花了list作爲參數,你可以在通過輸出printFirstArrow(randArrow())。 例如:

def printFirstArrow(arrows): 
    print arrows[0] 

printFirstArrow(randArrow()) // 'left' 
相關問題