Created
June 13, 2019 21:22
-
-
Save brenorb/a82b8e760080de872484460d5885fe34 to your computer and use it in GitHub Desktop.
Simple way to keep track of results printed but not returned
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# from https://www.kaggle.com/kmader/july-24-micro-challenge | |
from contextlib import redirect_stdout | |
from io import StringIO | |
def simulate_game(verbose=False): | |
out_buffer = StringIO() | |
with redirect_stdout(out_buffer): | |
blackjack.simulate_one_game() | |
out_str = out_buffer.getvalue() | |
if verbose: | |
print(out_str) | |
return any(['Player wins' in x for x in out_str.split('\n')]) # if any lines say player wins then we won | |
simulate_game(True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment