2017-11-20 38 views
0
def play(player_1_skill, player_1_strength,player_2_skill,player_2_strength,divider,skillmod,strengthmod): 
    strengthmod = math.floor((abs(player_1_strength - player_2_strength))/divider) 
    skillmod = math.floor((abs(player_1_skill - player_2_skill))/divider) 
    die_p1 = r.randint(1,6) 
    die_p2 = r.randint(1,6) 
    if player_1_strength > player_2_strength: 
     print("Player 1 Wins") 
     player_1_strength = strengthmod + player_1_strength 
     player_1_skill = skillmod + player_1_skill 
     player_2_strength = player_2_strength - strengthmod 
     player_2_skill = player_2_skill - skillmod 
    elif player_2_strength > player_1_strength: 
     print("Player 2 Wins") 
     player_2_strength = strengthmod + player_2_strength 
     player_2_skill = skillmod + player_2_skill 
     player_1_strength = player_1_strength - strengthmod 
     player_1_skill = player_1_skill - skillmod 
    else: 
     print("Tie") 

    print("The skill modifier : "+ str(skillmod)) 
    print("The strength modifier: " + str(strengthmod)) 
    print("Player 1, Your strength is: " + str(player_1_strength)) 
    print("Player 1, Your skill is: " + str(player_1_skill)) 
    print("Player 2, Your strength is: " + str(player_2_strength)) 
    print("Player 2 , Your skill is: " + str(player_2_skill)) 





    return (player_1_strength, player_1_skill, player_2_strength, player_2_skill,skillmod,strengthmod) 



play(player_1_skill, player_1_strength,player_2_skill, player_2_strength,divider,skillmod,strengthmod) 
play(player_1_skill, player_1_strength,player_2_skill, player_2_strength,divider,skillmod,strengthmod) 

私は戻ってバック関数に関数からの出力データを再入力する方法

+0

戻り値を変数に取り込み、変数を次の関数に渡します。 – AlG

答えて

1

最も簡単な方法は、された関数の中に同じ関数から 例えば機能データを出力し、出力データを別のデータを使用して関数を繰り返してはどうすればよいですこれらのデータを辞書に入れる。辞書と

例:

def play(player_1, player_2, divider): 
    # access the individual values like: 
    player_1['strength'] = ...something... 
    ...something... = player_2['skill']/divider 

# then 

player_1 = { 
    'strength': 10, 
    'skill': 20, 
} 
player_2 = { 
    'strength': 15, 
    'skill': 16, 
} 

play(player_1, player_2) 

今機能playはあなたが渡している辞書内の値を変更することができます。

関連する問題