Skip to content

Instantly share code, notes, and snippets.

@bverbeken
Created October 11, 2018 15:14
Show Gist options
  • Save bverbeken/f57122c7f4697a5bd1d9565862308b48 to your computer and use it in GitHub Desktop.
Save bverbeken/f57122c7f4697a5bd1d9565862308b48 to your computer and use it in GitHub Desktop.
import random
class RollAbilitiesAttempt:
def __init__(self):
self.rolls = self.roll_abilities()
def roll_abilities(self):
rolls = list()
for x in range(6):
rolls.append(self.roll_ability())
return rolls;
def roll_ability(self):
dice_rolls = self.roll_dice(4)
lowest = min(dice_rolls)
dice_rolls.remove(lowest)
return sum(dice_rolls)
def roll_dice(self, dice_count):
result = list()
for i in range(0, dice_count):
result.append(self.roll_die())
return result
def roll_die(self):
return random.randint(1, 6)
def pretty_print(self):
print("rolls: ")
print(self.rolls)
print("total: ")
print(self.total())
def total(self):
return sum(self.rolls)
def canBeRetried(self):
return self.total() < 70
def shallWeRetry():
yesno = raw_input("Scores were low. Do you want to retry? (y/n)")
if (yesno != 'y' and yesno != 'n'):
return shallWeRetry()
elif (yesno == 'y'):
return True
else:
return False
def newAttempt():
attempt = RollAbilitiesAttempt()
attempt.pretty_print()
if (attempt.canBeRetried()):
if (shallWeRetry()):
newAttempt()
else:
print "ok!"
newAttempt()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment