rendered paste bodyimport randomdef d(n, sides): roll = [random.choice(range(1, int(sides) + 1)) for x in range(int(n))] roll.sort(reverse = True) return(roll)def printRoll(n, d, rollList, modifier): dLine = "### Rolling: " + str(n) + "d" + str(d) rollLine = "### roll = " + str(rollList) subtotalLine = "### subtotal = " + str(sum(rollList)) modifierLine = "### modifier = " + str(modifier) resultLine = "### RESULT: " + str(sum(rollList) + modifier) tLen = max([len(x) + 3 for x in [rollLine, subtotalLine, resultLine, dLine, modifierLine]]) dLine += " "*(tLen - len(dLine)) + "###" rollLine += " "*(tLen-len(rollLine)) + "###" modifierLine += " "*(tLen - len(modifierLine)) + "###" subtotalLine += " "*(tLen-len(subtotalLine)) + "###" blankLine = "###" + " "*(tLen-3) + "###" resultLine += " "*(tLen-len(resultLine)) + "###" print("#" * (tLen + 3)) print(blankLine) print(dLine) print(rollLine) print(subtotalLine) print(modifierLine) print(blankLine) print(resultLine) print(blankLine) print("#" * (tLen + 3))def mod(strVar): try: neg = "-" in strVar if neg: return(-1 * int(strVar.strip(" +-."))) return(int(strVar.strip(" +-."))) except: return(0)while True: inVar = raw_input() try: inVarList = inVar.split() if (len(inVarList) == 3): modifier = mod(inVarList[1] + inVarList[2]) tmp = [int(x) for x in inVarList[0].split('d')] rollList = d(tmp[0], tmp[1]) printRoll(tmp[0], tmp[1], rollList, modifier) print("\r\n"*2) elif (len(inVarList) == 2): modifier = mod(inVarList[1]) tmp = [int(x) for x in inVarList[0].split('d')] rollList = d(tmp[0], tmp[1]) printRoll(tmp[0], tmp[1],rollList, modifier) print("\r\n"*2) elif (len(inVarList) == 1): tmp = inVar.split("d") n = int(tmp[0]) if ("+" in tmp[1]): tmp2 = tmp[1].split("+") d0 = int(tmp2[0]) modifier = int(tmp2[1]) elif ("-" in tmp[1]): tmp2 = tmp[1].split("-") d0 = int(tmp2[0]) modifier = (-1)*int(tmp2[1]) else: d0 = int(tmp[1]) modifier = 0 rollList = d(n, d0) printRoll(n, d0, rollList, modifier) print("\r\n"*2) inVar = "" inVarList = [] tmp = [] tmp2 = [] rollList = [] modifier = 0 d0 = 0 n = 0 except: try: print(eval(inVar)) except: errLine = "### Invalid Roll: " + inVar + " ###" print("\r\n"*2) print("#"*len(errLine)) print(errLine) print("#"*len(errLine)) print("\r\n"*2)