Here is a quick dice roller program I whipped up in Python. To run it, you’ll need to install Python3, which can be downloaded here. Then simply copy and paste this code into a new file and save with the .py file extension.
import random def diceRoller(numSides, numDie): #generates random number based on first parameter totalResult = 0 for i in range(numDie): rollResult = random.randint(1, numSides) totalResult = totalResult + rollResult print('The result of the roll is: ', totalResult) rollAgain = 'yes' while rollAgain == 'yes' or rollAgain == 'y': print('How many sides does this dice have(2-30)?') dice = int(input()) # error checker while dice < 2 or dice > 30: print('Please type a number between 2 and 30') dice = int(input()) print('How many dice of this type do you need to roll?') numDice = int(input()) diceRoller(dice, numDice) print('Do you want to roll again? (yes or no)') rollAgain = input()
Update (3/22/2013): Just noticed that the error checking code doesn’t work. I’ll fix it later.
Update (4/5/2013): Error checker fixed. Helps to use the correct logic (or, not and) 🙂