Created
February 10, 2016 00:55
-
-
Save vilmibm/76c59caf78409a83e472 to your computer and use it in GitHub Desktop.
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 random import randint | |
| def d6(): | |
| return randint(1,6) | |
| def explode(): | |
| print("explosion!") | |
| next_roll = d6() | |
| final = next_roll + 6 | |
| while next_roll == 6: | |
| print("explosion!") | |
| next_roll = d6() | |
| final += next_roll | |
| return final | |
| def roll(die, tn): | |
| results = [] | |
| for roll in range(die): | |
| result = d6() | |
| if result == 6: | |
| result = explode() | |
| results.append(result) | |
| print(results) | |
| if len(list(filter(lambda r: r == 1, results))) == len(results): | |
| return "catastrophic failure D:" | |
| elif len(list(filter(lambda r: r >= tn, results))) > 0: | |
| return "success :D" | |
| else: | |
| return "failure :(" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment