# Automatic Dice Roller # Written by Doug Blair from random import randrange print ("*Automatic Dice Roller*") print '\n' diceAmountType = raw_input("Enter dice amount and type as XdX: ") print (diceAmountType) diceModifier = raw_input("Enter dice modifier: ") print (diceModifier) print '\n' diceAmount = diceAmountType.split("d", 1)[0] diceType = int(diceAmountType.split("d", 2)[1]) total = 0 rollSum = 0 modifierSum = 0 natOnes = 0 natTwenties = 0 for x in range(1, (int(diceAmount) + 1)): roll = randrange(1, (diceType) + 1) totalRoll = (roll + int(diceModifier)) if diceType == 20: if roll == 1: natOnes += 1 print("Roll " + str(x) + ": " + "Natural 1 :(" + " (" + str(roll) + " + " + str(diceModifier) + ")") elif roll == 20: natTwenties += 1 print("Roll " + str(x) + ": " + "Natural 20! :)" + " (" + str(roll) + " + " + str(diceModifier) + ")") else: print("Roll " + str(x) + ": " + str(totalRoll) + " (" + str(roll) + " + " + str(diceModifier) + ")") else: print("Roll " + str(x) + ": " + str(totalRoll) + " (" + str(roll) + " + " + str(diceModifier) + ")") rollSum = rollSum + roll modifierSum = modifierSum + int(diceModifier) total = total + totalRoll print '\n' print ("Total: "+ str(total) + " (" + str(rollSum) + " + " + str(modifierSum) + ")") if diceType == 20: print ("Natural 1's: " + str(natOnes)) print ("Natural 20's: " + str(natTwenties))
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question