我正在嘗試創(chuàng)建一個 Martingale 投注模擬器。我的全局“running_profit”變量應(yīng)該由“change_running_total”函數(shù)間接更新。running_total 變量已正確更新,但受 running_total 影響的 running_profit 變量未更新。import randomround_n = 0bet = 25starting_funds = 5000running_total = starting_fundsrunning_profit = running_total - starting_fundsgoal_profit = 5000wins = 0losses = 0rng_v = 0.00def rng(): """Generates random number""" global rng_v rng_v = random.random()def winloss_generator(): """Generates win/loss condition""" global rng_v if rng_v <= .49: return 'win' else: return 'loss'def increase_winloss(): """Increases wins or losses variable based on winloss_generator output""" global wins global losses if winloss_generator() == 'win': wins += 1 return 'win' elif winloss_generator() == 'loss': losses += 1 return 'loss' else: print('error')def increase_round(): """Increases round number by 1""" global round_n round_n += 1 print('round: ', round_n)def change_running_total(): """Increases or decreases running_total based on winloss_generator""" global running_total if winloss_generator() == 'win': running_total += bet elif winloss_generator() == 'loss': running_total -= bet else: print('error')def print_current_record(): """Prints current win/loss record to screen""" print('Current Record: ', wins, 'wins, ', losses, 'losses')def print_winloss(): """Prints win/loss condition to screen""" print(winloss_generator(), 'print_winloss'.upper())def print_profit(): """Print running profit to screen""" print(running_profit, 'print_profit (variable)'.upper()) print(running_total - starting_funds, 'print_profit (calculated)'.upper())def return_current_funds(): """Returns running total of funds""" global running_total return running_total
為什么我的 running_profit 變量沒有更新?
HUH函數(shù)
2023-08-08 17:47:23